Hello!
Here is another simple app
This automation is not final or complete, and probably there is a way to make more generic. My aim is to share examples that maybe can help new members starting with HA+AppDaemon.
Suggestions or recommendations to improve the implementation are welcome!
App #3: Smart Radiator
Turn off the radiator of the LIVING_ROOM if one of its windows is opened.
Entities
binary_sensor.livingroom_window1
binary_sensor.livingroom_window2
switch.livingroom_radiator
groups.yaml
lr_windows:
name: LR Windows
view: yes
entities:
- binary_sensor.livingroom_window1
- binary_sensor.livingroom_window2
app.yaml
smart_radiator:
module: smart_radiator
class: SmartRadiator
windows: group.lr_windows
radiator: switch.livingroom_radiator
smart_radiator.py
import appdaemon.plugins.hass.hassapi as hass
class SmartRadiator(hass.Hass):
def initialize(self):
self.log('initializing ...')
group = self.get_state(self.args["windows"], attribute = "all")
sensors = group["attributes"]["entity_id"]
for sensor in sensors:
self.log(f'Subscribing to: {self.friendly_name(sensor)}')
self.listen_state(self.on_windows_open, sensor, new="on")
def on_windows_open(self, entity, attribute, old, new, kwargs):
radiator = self.args["radiator"]
if self.get_state(radiator) == "on":
self.log(f'Turning off the {self.friendly_name(radiator)} ')
self.turn_off(radiator)
else: # only for debugging purposes
self.log(f'The {self.friendly_name(radiator)} is off, enjoy the fresh air ...')
Note: This implementation is not generic, but that it’s on the pipeline
Happy coding!
Humberto
Edit #1 Avoid hardcode entities names in the automation code. Thanks @swiftlyfalling @Burningstone
Previous post: App #2: Smart Light
Next post: App #4: Boiler Alert