Skip to content

Commit

Permalink
added control of custom programmed arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schröder committed Aug 2, 2023
1 parent 520360d commit d14a687
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 150 deletions.
214 changes: 64 additions & 150 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
support:
- homeassistant
devices:
- name: Befehle
id: command
class: Command
- name: Bluetooth
id: bluetooth
class: Bluetooth
- name: HS-Can
id: hscan
class: Socketcan
connection:
bus: can0
- name: PWM-Controller
id: pwmcontroller
class: PCA9685
connection:
type: i2c
bus: 1
channels:
- name: Licht Dachluke
id: 0
type: light
- name: Licht Schiebetür links
id: 1
type: light
- name: Licht Schiebetür rechts
id: 2
type: light
- name: Licht Laderaum
id: 3
type: light
- name: Licht5
id: 4
type: light
- name: Schubladenverrieglung
id: 14
min: 400
max: 2600
scale: 180
- name: Kühlschrankverrieglung
id: 15
min: 400
max: 2600
scale: 180

- name: Analogsensor
id: analogsensor
class: ADS1115
Expand All @@ -57,132 +13,90 @@ devices:
measure: 0+GND
min: 0
max: 65535
scale: 1
unit: l
scale: 100
unit: "%"
- name: A1
measure: 1+GND
min: 0
max: 65535
scale: 1
unit: l
- name: Abwasser
scale: 100
unit: "%"
- name: A2
measure: 2+GND
min: 1400
max: 14000
scale: 78
unit: l
- name: Frischwasser
min: 0
max: 65535
scale: 100
unit: "%"
- name: A3
measure: 3+GND
min: 0
max: 14400
scale: 110
unit: l
- name: Luftsensor
id: luftsensor
class: BME280
connection:
type: i2c
bus: 1
- name: Helligkeitssensor
id: helligkeitssensor
class: BH1750
connection:
type: i2c
bus: 1
- name: Bewegungssensor
id: bewegungssensor
class: MPU_6050
connection:
type: i2c
bus: 1
- name: B2B-Laderegler
id: b2b_laderegler
class: Votronic_VCC_1212
connection:
type: serial
port: "/dev/ttyUSBCharger"
- name: Solar-Laderegler
id: solar_laderegler
class: Ective_DSC
connection:
type: serial
port: "/dev/ttyUSBSolar"
- name: Wechselrichter
id: wechselrichter
class: Ective_CSI
connection:
type: pins
power_pin: 17
mode_pin: 27
data_pin: 22
- name: Dieselheizung
id: dieselheizung
class: Autoterm_Air_2D
subscribe:
temperature_current: connector/device/luftsensor/temperature/state
connection:
type: serial
port: "/dev/ttyUSBHeater"
max: 65535
scale: 100
unit: "%"
- name: GPIO
id: gpio
class: GPIO
connection:
host: localhost
pins:
- name: Dashcam
type: out
id: 24
inverted: true
- name: Wasserpumpe
type: out
id: 31
inverted: true
- name: Kühlschrank
- name: 'Relais #1'
type: out
id: 36
inverted: true
- name: B2B Laderegler
id: 11
- name: 'Relais #2'
type: out
id: 38
inverted: true
- name: Soundsystem
id: 13
- name: 'Relais #3'
type: out
id: 22
inverted: true
- name: Relais 1
type: out
id: 28
inverted: true
- name: Relais 2
id: 15
- name: 'Relais #4'
type: out
id: 16
inverted: true
- name: Relais 3
id: 19
- name: 'Relais #5'
type: out
id: 26
inverted: true
- name: Wasserboiler
id: 21
- name: 'Relais #6'
type: out
id: 8
inverted: true
- name: '230V #2'
id: 23
- name: 'Relais #7'
type: out
id: 10
inverted: true
- name: 12V Spannungsregler
id: 27
- name: 'Relais #8'
type: out
id: 18
- name: Schalter Dachluke
id: 29
- name: 'Button #1'
type: in
id: 7
id: 33
pull: up
inverted: true
- name: Haupttaster
- name: 'Button #2'
type: in
id: 40
pull: up
inverted: true
- name: Soundsystem
id: sound
class: Pulseaudio
controls:
- name: Main
id: Master
id: 32
pull: down
- name: 'PWM'
type: pwm
id: 32
- name: Lichtsteuerung außen
id: lichtsteuerung_aussen
class: Arduino
connection:
type: i2c
bus: 1
lights:
- name: 'Fernlicht links'
- name: 'Fernlicht rechts'
- name: 'Rücklicht links'
- name: 'Rücklicht rechts'
- name: 'Licht #5'
- name: 'Licht #6'
- name: 'Licht #7'
brightness: true
- name: 'Licht #8'
brightness: true
- name: 'Licht #9'
brightness: true
- name: 'Licht #10'
brightness: true
- name: 'Licht #11'
brightness: true
- name: 'Licht #12'
brightness: true
63 changes: 63 additions & 0 deletions device/Arduino.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import i2c from 'i2c-bus'
import Device from './base.js'

const ADDRESS = 0x08
const BRIGHTNESS_SCALE = 255

export default class extends Device {
constructor (config) {
super(config)

this.manufacturer = 'Arduino'
this.model = 'Light Controller'
this.version = '1'
this.bus = null
}

async connect () {
const { connection } = this.config

this.bus = i2c.openSync(parseInt(connection.bus))
this.poll(10000, () => Array.from({ length: 12 }).forEach((v, i) => this.emit(i)))
}

emit (i) {
const light = this.config.lights[i] || {}
const brightness = light.brightness
let value

try {
value = this.bus.readByteSync(ADDRESS, i)

this.emitEntity({
type: 'light',
key: 'light' + i,
name: light.name || 'Light #' + i,
brightness,
brightnessScale: brightness ? BRIGHTNESS_SCALE : undefined,
commands: [ 'command' ],
states: {
state: JSON.stringify({
state: value === 0 ? 'OFF' : 'ON',
...(brightness && { brightness: value })
})
}
})
} catch (error) {
this.error(error)
}
}

handle (key, command, value) {
const id = parseInt(key.slice(5))

value = JSON.parse(value)

if (id > 5 && value.state === 'ON' && !('brightness' in value)) {
value.brightness = BRIGHTNESS_SCALE
}

this.bus.writeByteSync(ADDRESS, id, value.state === 'ON' ? value.brightness || 1 : 0)
this.emit(id)
}
}

0 comments on commit d14a687

Please sign in to comment.