This can’t be hard but I haven’t quite figured out how to tackle this so I am asking for help to point me in the right direction.
I want a lovelace switch to be flicked “OFF” if two device trackers report “away” (AND) and turned “ON” when either one of the devicetrackers switches to “home” (OR).
Should this best be a time based trigger checking like every two minutes, or a template trigger or…?
The OR case is easy as this is the native mode for multiple triggers. If any of the triggers are true the automation will trigger. Simply add the two trackers as triggers and check for state: “home”.
The AND case can use the same trigger set up (in a seperate automation) but looking for state: ‘not_home”. Then add two state conditions. Both trackers must be ‘not_home’ for the automation to run. Conditions are AND by default.
Heh. Just spotted them and did so. That’s the trouble using an iPad in bed. I actually had to copy and paste the right type. The single quotes the iPad uses are the wrong type.
I added this to the automation.yaml file (I am on HASS.IO). I get one error message in the user interface because more than one triggers aren’t allowed yet (in the GUI) but I guess I can ignore that.
Failed config
automation:
- Invalid config for [automation]: required key not provided @ data['trigger'][0]['platform']. Got None. (See /config/configuration.yaml, line 158). Please check the docs at https://home-assistant.io/components/automation/
So, in HASS.IO you have to go through the GUI, you can’t just edit the automations.yaml file.
But in the end, this is how it looks, the modifications are very slight.
- id: '1542118454340'
alias: Bilderrahmen an, wenn einer zuhause ist
trigger:
- entity_id: device_tracker.wolfgangx
platform: state
to: home
- entity_id: device_tracker.tanjaiphone6
platform: state
to: home
condition: []
action:
- data:
entity_id: switch.bilderrahmen
service: switch.turn_on
- id: '1542118682597'
alias: Bilderrahmen aus, wenn keiner zuhause ist
trigger:
- entity_id: device_tracker.wolfgangx
platform: state
to: not_home
- entity_id: device_tracker.tanjaiphone6
platform: state
to: not_home
condition:
- condition: state
entity_id: device_tracker.tanjaiphone6
state: not_home
- condition: state
entity_id: device_tracker.wolfgangx
state: not_home
action:
- data:
entity_id: switch.bilderrahmen
service: switch.turn_off
Silly question:
Why not just put both trackers in a group and have the group state change trigger the actions, i.e. no fussing about with all the conditions?
Or am I missing something important here?
And you really just can’t simply edit the automation code in the respective yaml-file in hass.io?
I’m not using hass.io so I’m just trying to understand.
And I tried to use the GUI to manage my automations waaay back when it was introduced - it seriously s%$@#& up most of them at that point in time. So I kept doing it manually and never tried again