Hi all,
I’m trying to create an automation that will
- when a person/car/dog from the camera is detected
- play audio tone on smart speaker at a certain volume level
- blink wled lights using a specific preset
Additionally, it should reset the speaker and wled lights back to their previous state. For the speaker that means get the volume level before playing the sound and set the volume back to the original level after the audio plays. For the light that would entail 2 things: 1) set back to previous light state (on/off) and 2) set back to previous wled preset that it was set to.
The audio portion works correctly. The wled portion is unable to detect the preset that wled was set to before the automation runs. It does correctly turn the light on/off back to it’s original state before the automation runs.
One potentially important detail is my WLED controller is always powered on, however there is a relay to the light strip that will physically turn the lights on/off so they’re not powered when they’re off (there’s always current otherwise, even with 0 lights being on). This should mean HA should be able to get the light state at any time in my mind, because the device itself is on.
With the help of Grok troubleshooting (which has been helping with the automation as well as this is beyond me), I set up a jinja template to see the wled states when the light is both ‘on’ and ‘off’:
Light State: {{ states('light.dig_quad_v3_main') }}
Preset State: {{ states('select.dig_quad_v3_preset') }}
Full Light Attributes: {{ state_attr('light.dig_quad_v3_main', 'attributes') | tojson }}
results:
Light State: off
Preset State: unknown
Full Light Attributes: null
Light State: on
Preset State: unknown
Full Light Attributes: null
So it seems the data isn’t available? I’m not sure where to go from here. Any ideas? Thank you!
description: Triggers an audio alert on Sat1 when camera detects a person, car or dog
triggers:
- trigger: mqtt
options:
topic: frigate/events
conditions:
- condition: template
value_template: >-
{{ trigger.payload_json is defined and trigger.payload_json['after'] is
defined and trigger.payload_json['after']['label'] in ['person', 'car',
'dog'] and trigger.payload_json['after']['score'] > 0.75 and (now() |
as_timestamp - (states('input_datetime.last_alert_time') | as_timestamp |
default(0))) > (60*5) }}
actions:
- data:
entity_id: input_datetime.last_alert_time
datetime: "{{ now() }}"
action: input_datetime.set_datetime
- variables:
media_player_entity: media_player.satellite1_929988_sat1_media_player
current_volume: "{{ state_attr(media_player_entity, 'volume_level') | float(0) }}"
light_entity: light.dig_quad_v3_main
preset_entity: select.dig_quad_v3_preset
original_light_state: "{{ states(light_entity) }}"
original_preset: "{{ states(preset_entity) if states(preset_entity) not in ['unknown', 'unavailable'] else none }}"
- if:
- condition: and
conditions:
- condition: template
value_template: "{{ original_light_state == 'off' }}"
- condition: template
value_template: "{{ original_preset is none }}"
then:
- action: light.turn_on
target:
entity_id: "{{ light_entity }}"
- delay:
milliseconds: 1000 # Give time for preset state to update (this doesn't seem to affect anything)
- variables:
original_preset: "{{ states(preset_entity) if states(preset_entity) not in ['unknown', 'unavailable'] else 'Flow' }}"
- action: light.turn_off
target:
entity_id: "{{ light_entity }}"
- data:
entity_id: "{{ media_player_entity }}"
volume_level: 0.4
action: media_player.volume_set
- data:
entity_id: "{{ media_player_entity }}"
announce: true
media:
media_content_id: media-source://media_source/local/mixkit-digital-quick-tone-2866.wav
media_content_type: audio/x-wav
metadata: {}
action: media_player.play_media
- delay:
seconds: 1.6
- data:
entity_id: "{{ media_player_entity }}"
volume_level: "{{ current_volume }}"
action: media_player.volume_set
- action: light.turn_on
target:
entity_id: "{{ light_entity }}"
- delay:
milliseconds: 500
- action: select.select_option
target:
entity_id: "{{ preset_entity }}"
data:
option: "AlertBlink"
- delay:
seconds: 2
- if:
- condition: template
value_template: "{{ states(preset_entity) != original_preset }}"
then:
- action: select.select_option
target:
entity_id: "{{ preset_entity }}"
data:
option: "{{ original_preset }}"
- if:
- condition: template
value_template: "{{ original_light_state == 'off' }}"
then:
- action: light.turn_off
target:
entity_id: "{{ light_entity }}"
mode: single