(Sorry for the broken english)
Hello, I’m still trying to connect all the dots as I’m fairly new to HA.
I set up a couple of Ikea Vallhorn motion sensors and as far as the basic functioning goes I’m satisfied.
What I was trying to do, though, was to have the lights change based both on the motion and the state of the TV in that same room.
Basically: Movement and TV of or paused → scene 1; movement and tv is playing → scene 2.
Also: scene 1 is loaded and tv resumes playing → scene 2; scene 2 is loaded and tv is paused → scene 1.
I’m using a boolean helper changed by these automations:
alias: Megatron in riproduzione
description: ""
triggers:
- trigger: state
entity_id:
- media_player.megatron_3
from: null
to:
- playing
conditions: []
actions:
- action: input_boolean.turn_on
metadata: {}
target:
entity_id: input_boolean.film_mode_taverna
data: {}
mode: single
alias: Megatron Stop Riproduzione
description: ""
triggers:
- trigger: state
entity_id:
- media_player.megatron_3
from:
- playing
to: null
conditions: []
actions:
- action: input_boolean.turn_off
metadata: {}
target:
entity_id: input_boolean.film_mode_taverna
data: {}
mode: single
I’ll be frank, I haven’t touched code since I was using turbo pascal in school decades ago, so I turned to chat gpt to try and fix it. It is my understanding that
mode: restart
should run the whole automation from scratch any time a trigger event happens… but the result is that the llight is not changing dinamically as I wish and also the lights turn off while I’m in the room moving for longer than 30 seconds.
I’m aware that this might need a whole redo, but at this point I’m just curious to understand what is wrong with the logic (or the syntax) of this automation.
Any help or insight is greatly appreciated.
(and btw the second sensor was moved form a room to another. I changed the name in HA but the entity names stayed the same. If I regenerate the entity name will the automation change as well or will it be broken?)
alias: Tavernabis
description: ""
triggers:
- trigger: binary_sensor.occupancy_detected
target:
entity_id:
- binary_sensor.cucina_movimento_occupancy
- binary_sensor.taverna_rilevatore_ingresso_occupancy
options:
behavior: any
- trigger: state
entity_id:
- input_boolean.film_mode_taverna
from: null
to: null
conditions:
- condition: light.is_off
target:
entity_id:
- light.luci_tv
- light.taverna_luci_piantana
- light.taverna_luci_piantana_braccio
- light.taverna_luci_cucinino
options:
behavior: all
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.cucina_movimento_occupancy
state:
- "on"
- condition: state
entity_id: binary_sensor.taverna_rilevatore_ingresso_occupancy
state:
- "on"
actions:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.film_mode_taverna
state:
- "on"
sequence:
- action: scene.turn_on
metadata: {}
target:
entity_id: scene.taverna_movie
data: {}
- conditions:
- condition: state
entity_id: input_boolean.film_mode_taverna
state:
- "off"
sequence:
- action: scene.turn_on
metadata: {}
target:
entity_id: scene.luci_di_presenza
data: {}
- wait_for_trigger:
- trigger: state
entity_id:
- binary_sensor.cucina_movimento_occupancy
- binary_sensor.taverna_rilevatore_ingresso_occupancy
from:
- "on"
to:
- "off"
for:
hours: 0
minutes: 0
seconds: 30
- action: scene.turn_on
metadata: {}
target:
entity_id: scene.luci_spente
data: {}
mode: restart