I agree with that, but unless I completely misunderstand how things work, there isn’t really any way for me to make a custom automation component is there?
I think the most interestting one is the mirror state (everything is in dutch I’m afraid):
import appdaemon.plugins.hass.hassapi as hass
class MirrorSource(hass.Hass):
def initialize(self):
if 'target_lamp' in self.args and 'source_switch' in self.args:
self.listen_state(self.spiegel_switch_lamp, self.args['source_switch'])
elif 'target_switch' in self.args and 'source_switch' in self.args:
self.listen_state(self.spiegel_switch_switch, self.args['source_switch'])
elif 'target_lamp' in self.args and 'source_lamp' in self.args:
self.listen_state(self.spiegel_lamp_lamp, self.args['source_lamp'])
elif 'target_switch' in self.args and 'source_lamp' in self.args:
self.listen_state(self.spiegel_lamp_switch, self.args['source_lamp'])
def spiegel_switch_lamp(self, entity, attribute, old, new, kwargs):
if self.get_state(self.args['target_lamp']) != new:
self.toggle(self.args["target_lamp"])
def spiegel_switch_switch(self, entity, attribute, old, new, kwargs):
if self.get_state(self.args['target_switch']) != new:
self.toggle(self.args["target_switch"])
def spiegel_lamp_lamp(self, entity, attribute, old, new, kwargs):
self.spiegel_switch_lamp(entity, attribute, old, new, kwargs)
def spiegel_lamp_switch(self, entity, attribute, old, new, kwargs):
self.spiegel_switch_switch(entity, attribute, old, new, kwargs)
class MirrorBoth(hass.Hass):
def initialize(self):
if 'target_lamp' in self.args and 'source_switch' in self.args:
self.listen_state(self.spiegel_switch_lamp, self.args['source_switch'])
self.listen_state(self.spiegel_switch_lamp, self.args['target_lamp'])
elif 'target_switch' in self.args and 'source_switch' in self.args:
self.listen_state(self.spiegel_switch_switch, self.args['source_switch'])
self.listen_state(self.spiegel_switch_switch, self.args['target_switch'])
elif 'target_lamp' in self.args and 'source_lamp' in self.args:
self.listen_state(self.spiegel_lamp_lamp, self.args['source_lamp'])
self.listen_state(self.spiegel_lamp_lamp, self.args['target_lamp'])
elif 'target_switch' in self.args and 'source_lamp' in self.args:
self.listen_state(self.spiegel_lamp_switch, self.args['source_lamp'])
self.listen_state(self.spiegel_lamp_switch, self.args['target_switch'])
def spiegel_switch_lamp(self, entity, attribute, old, new, kwargs):
if entity == self.args['source_switch']:
if self.get_state(self.args['target_lamp']) != new:
self.toggle(self.args["target_lamp"])
if entity == self.args['target_lamp']:
if self.get_state(self.args['source_switch']) != new:
self.toggle(self.args["source_switch"])
def spiegel_switch_switch(self, entity, attribute, old, new, kwargs):
if entity == self.args['source_switch']:
if self.get_state(self.args['target_switch']) != new:
self.toggle(self.args["target_switch"])
if entity == self.args['target_switch']:
if self.get_state(self.args['source_switch']) != new:
self.toggle(self.args["source_switch"])
def spiegel_lamp_switch(self, entity, attribute, old, new, kwargs):
if entity == self.args['source_lamp']:
if self.get_state(self.args['target_switch']) != new:
self.toggle(self.args["target_switch"])
if entity == self.args['target_switch']:
if self.get_state(self.args['source_lamp']) != new:
self.toggle(self.args["source_lamp"])
def spiegel_lamp_lamp(self, entity, attribute, old, new, kwargs):
if entity == self.args['source_lamp']:
if self.get_state(self.args['target_lamp']) != new:
self.toggle(self.args["target_lamp"])
if entity == self.args['target_lamp']:
if self.get_state(self.args['source_lamp']) != new:
self.toggle(self.args["source_lamp"])
And it is used like this:
garderobekastlicht:
module: mirror_state
class: MirrorSource
source_switch: binary_sensor.garderobekast_deur
target_switch: switch.plug_garderobekast_switch
constrain_input_boolean: binary_sensor.time_bed,off
The mirrorBoth is imo the most interesting, but I’m not using it anymore at the moment. It was used to sync a switch that was tied to the cabinetlights. If the lights would come on/off by some automation, the switch would also change state (it was a touch sensor with an LED for the state). And obviously, flipping the switch would change the light.
And an example of a simple automation is buttons exposed by deconz:
import appdaemon.plugins.hass.hassapi as hass
class DeconzButton(hass.Hass):
def initialize(self):
if 'multiple_service' in self.args:
self.listen_event(self.handle_event_multiple, 'deconz_event', id = self.args['id'])
else:
self.listen_event(self.handle_event, 'deconz_event', id = self.args['id'])
def handle_event(self, event_name, data, kwargs):
if data['event'] == 1002: # Single press
self.call_service(self.args['single_service'], **self.args['single_data'])
elif data['event'] == 1004: # Double
self.call_service(self.args['double_service'], **self.args['double_data'])
elif data['event'] == 1005: # Triple
self.call_service(self.args['triple_service'], **self.args['triple_data'])
def handle_event_multiple(self, event_name, data, kwargs):
if data['event'] == 1002: # Single press
self.call_service(self.args['single_service'], **self.args['single_data'])
elif data['event'] == 1004: # Double
self.call_service(self.args['multiple_service'], **self.args['multiple_data'])
class DeconzButton_double(hass.Hass):
def initialize(self):
self.listen_event(self.handle_event, 'deconz_event', id = self.args['id'])
def handle_event(self, event_name, data, kwargs):
if data['event'] == 1002: # Left press
self.call_service(self.args['left_service'], **self.args['left_data'])
elif data['event'] == 2002: # Right press
self.call_service(self.args['right_service'], **self.args['right_data'])
knop_slaapkamer:
module: deconz_button
class: DeconzButton
id: slaapkamer_knop
single_service: scene/turn_on
single_data: {"entity_id": "scene.alles_uit_slaapkamer"}
multiple_service: scene/turn_on
multiple_data: {"entity_id": "scene.alles_aan_slaapkamer"}
dubbele_knop_bank:
module: deconz_button
class: DeconzButton_double
id: aqara_switch2
left_service: light/toggle
left_data: {"entity_id": "light.stalamp_bank"}
right_service: light/toggle
right_data: {"entity_id": "light.tv_dimmer_level"}
knop_eettafel:
module: deconz_button
class: DeconzButton
id: woonkamer_knop
single_service: light/toggle
single_data: {"entity_id": "light.eettafel_dimmer_level"}
double_service: light/turn_on
double_data: {"entity_id": "light.eettafel_dimmer_level", "brightness_pct" : 100}
triple_service: light/turn_on
triple_data: {"entity_id": "light.eettafel_dimmer_level", "brightness_pct" : 1}
Obviously this is also not hard per se in home assistant itself, but I think this abstracts it better for the user. I think buttons might be solved by the device implementation though.