Hi,
I’ve just written a service for this, I start too learn python 3 and HA.
import time as t
from .smbus2 import SMBus
DOMAIN = “relay_switch”
DEVICE_ADDR = 0x10
DEVICE_BUS = 1
def setup(hass, config):
def demo(call):
bus = SMBus(DEVICE_BUS)
for i in range(1,5):
bus.write_byte_data(DEVICE_ADDR, i, 0xFF)
t.sleep(1)
bus.write_byte_data(DEVICE_ADDR, i, 0x00)
t.sleep(1)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'demo', demo)
def option_yokis(call):
DEFAULT_RELAY = 1
DEFAULT_REPEAT = 1
relay = call.data.get("relay", DEFAULT_RELAY)
repeat = call.data.get("repeat", DEFAULT_REPEAT)
bus = SMBus(DEVICE_BUS)
for i in range(0,repeat):
bus.write_byte_data(DEVICE_ADDR, relay, 0xFF)
t.sleep(0.1)
bus.write_byte_data(DEVICE_ADDR, relay, 0x00)
t.sleep(0.2)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'option_yokis', option_yokis)
def switch(call):
DEFAULT_RELAY = 1
relay = call.data.get("relay", DEFAULT_RELAY)
bus = SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, relay, 0xFF)
t.sleep(0.5)
bus.write_byte_data(DEVICE_ADDR, relay, 0x00)
t.sleep(0.5)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'switch', switch)
def turn_on_parking(call):
bus = SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 1, 0xFF)
t.sleep(0.5)
bus.write_byte_data(DEVICE_ADDR, 1, 0x00)
t.sleep(0.5)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'turn_on_parking', turn_on_parking)
def turn_off_parking(call):
bus = SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 2, 0xFF)
t.sleep(0.5)
bus.write_byte_data(DEVICE_ADDR, 2, 0x00)
t.sleep(0.5)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'turn_off_parking', turn_off_parking)
def turn_on_chemin(call):
bus = SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 3, 0xFF)
t.sleep(0.5)
bus.write_byte_data(DEVICE_ADDR, 3, 0x00)
t.sleep(0.5)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'turn_on_chemin', turn_on_chemin)
def turn_off_chemin(call):
bus = SMBus(DEVICE_BUS)
bus.write_byte_data(DEVICE_ADDR, 4, 0xFF)
t.sleep(0.5)
bus.write_byte_data(DEVICE_ADDR, 4, 0x00)
t.sleep(0.5)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'turn_off_chemin', turn_off_chemin)
# Return boolean to indicate that initialization was successfully.
return True