I have hacked my amazon button so it triggers an automation i have written in home assistant. This automation turns everything off in my house.
The thing is, as i can only add one action to a dash, it wont turn everything back on once iv turned everything off. Its simply an off button for everything currently.
Im looking to try and automate this by using a lamp as the state to see whether thats on and call the appropriate on/off automation script. I never want this automation to fire unless i call it, which is why i used media_player.kodi as i never use it now.
At the moment, i have 1 automation to turn off all devices, one to turn on all automations, and one which makes the decision which is what the dash button will call - which is where i am stuck.
There might be an easier way to do this so im all ears!
here’s what i have;
automation dash button off:
alias: dash off
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: media_player.kodi
to: 'stopped'
action:
- service: homeassistant.turn_off
entity_id: light.large_l,light.small_l,light.stairs,light.kitchen,switch.testing_hyperion,media_player.sony_tv
- service: homeassistant.turn_on
entity_id: switch.kodi_input_amp
automation dash button on:
alias: dash on
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: media_player.kodi
to: 'stopped'
action:
- service: homeassistant.turn_on
entity_id: light.large_l,light.small_l,light.stairs,light.kitchen,switch.testing_hyperion,media_player.sony_tv
- service: homeassistant.turn_on
entity_id: switch.television_input_amp
automation dash button:
alias: Dash button - all off
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: media_player.kodi
to: 'stopped'
action:
- service: automation.trigger
data_template:
entity_id: >-
{% if is_state('light.large_l', 'off') %}
automation.dash_on
{% else %}
automation.dash_off
{% endif %}
Make two scenes. One that turns on all of your devices, and one that turns off all your devices. Call them dash_on and dash_off.
Then, write an automation that triggers based on the dash button (doesn’t look like you have that part in your example) and using a data template for the light as you’ve done should work for the action.
I’m a bit mystified about the media player condition - what’s that for?
Try:
- alias: Dash button
trigger:
- [here you need to put whatever the dash button does]
action:
- service: scene.turn_on
data_template:
entity_id: >-
{% if is_state('light.large_l', 'off') %}
scene.dash_on
{% else %}
scene.dash_off
{% endif %}
I was only using kodi i was going down the automation calling another automation route, so i needed something that wouldnt actually fire but could be triggered. But your examples makes alot more sense!
Just trying it now, ill let you know how i get on.
- [here you need to put whatever the dash button does]
Not wuite sure what to put here, my dash button basically sends json and i have dasher listening for any messages:
Yes they are, but that’s why I suggested originally that you should be using a script for this rather than an automation. And then in your dash button config you’d replace automation/trigger with script/turn_on like so:
You can have conditions in scripts: see https://home-assistant.io/docs/scripts/. Conditions are evaluated in order and execution of the script only continues if the condition returns “true”.