So I have this automation that turns on lights in my theater room after I turn off the TV. I then usually leave the room and the lights turn off later. I also have a script that turns on a harmony activity that I created that resets the soundbar volume. Overall it “works” but only after I’ve triggered it manually once. I’m sure its the condition, maybe a better way. Bottom line after it finishes, it would keep running over and over. I could have two automations, or some other sensor, input boolean, I guess, but this seemed like such a simple solution at first.
Just looking for suggestions
- alias: Turn on Lights in room after TV turns off
trigger:
- platform: state
entity_id: remote.theater_room_harmony_hub
to: 'off'
condition:
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.turn_on_lights_in_room_after_tv_turns_off.attributes.last_triggered) | int > 300 }}'
action:
- service: light.turn_on
data:
entity_id:
- light.frog_ceiling_light
- light.frog_fan_light
brightness: 40
- delay:
seconds: 120
- service: light.turn_off
data:
entity_id:
- light.frog_ceiling_light
- light.frog_fan_light
- service: homeassistant.turn_off
entity_id: fan.frog_fan
- service: script.turn_on
entity_id: script.theater_room_soundbar_reset
- delay:
seconds: 90
- service: script.turn_on
entity_id: script.theater_room_harmony_hub_off
Ok, maybe still not the best. So if I accidentally turn off the remote and then back on the automation continues to run.
So here’s what I’m looking to do, and looking for recommendations on the workflow. Any help is appreicated
When I turn off my hub, I want the lights to turn on right away
Two minutes later I want to turn off the lights and the fan
A bit after that I want to run a script that actually runs a harmony activity (soundbar reset)
About 90 seconds later turn off the Harmony (this gives the harmony activity enough to finish)
The soundbar reset basically just sends about 20 volume down commands and then 10 volume up commands to my soundbar. It does not have a volume set capability.
Main thing is that if I use the Harmony turning off as the trigger I need to have some sort of condition to keep it from running over and over. And as I found out, I’d like it to stop running or cancel if I turn it off and right back on. But I cannot really use the “off for X seconds” as the trigger or I’m sitting there in the dark after the TV turns off.
Didn’t completely follow that. Is the problem that step 4 causes the trigger in step 1?
If so I’d add a step between 3 and 4 that turns on an input_boolean and a step after 4 that turns the input_boolean back off. Then add a condition to the automation that the input_boolean is off (which effectively disables the trigger in step 1.)
(I’d give a more concrete example, except I’m writing this on my phone.)
input_boolean:
is_dirty:
name: is my power off sequence dirty
initial: off
icon: mdi:delete
- alias: Turn on Lights in room after TV turns off
trigger:
- platform: state
entity_id: remote.theater_room_harmony_hub
to: 'off'
condition:
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.turn_on_lights_in_room_after_tv_turns_off.attributes.last_triggered) | int > 300 }}'
action:
service_template: "{{ 'script.turn_off_dirty' if is_state('input_boolean.is_dirty','on') else 'script.shutdown_sequence' }}