#what is the actual code of the trigger
1 messages · Page 1 of 1 (latest)
The trigger is a volume change. Then need to figure out if it's increasing or decreasing and act accordingly.
I'm just thinking of a way to get the current volume and compare it to last but not entirely sure of how to do that.
Please share the yaml code
`platform: state
entity_id:
- media_player.kirchen_tv
attribute: volume_level
`
how does this help?
Now I know which trigger variables are available
I see.
ok
Maybe storing last volume level in a variable and then comparing it to current can do the job?
platform: state
entity_id:
- media_player.kirchen_tv
attribute: volume_level
variables:
increase: "{{ trigger.from_state.attributes.volume_level | is_number and trigger.from_state.attributes.volume_level < trigger.to_state.attributes.volume_level }}"
If you use this trigger you will have a variabele increase which will be true in case the volume was increased
Small fix (forgot the ending quotes)
That is_number thing, is it required? Volume level is always a number isn't it?
Not if your device turns on, or is unavailable for a moment
problem is that this works when the device turns off and on as well. since the volume changes from 0 to whatever it was last time and vice versa.
It doesn't change from whatever to 0, the attribute will not exist when the media player is off
trigger:
- platform: state
entity_id:
- media_player.kirchen_tv
attribute: volume_level
condition:
- condition: template
value_template: "{{ trigger.from_state.attributes.get('volume_level') | is_number and trigger.to_state.attributes.get('volume_level') | is_number }}"
action:
- variables:
increase: "{{ trigger.from_state.attributes.volume_level < trigger.to_state.attributes.volume_level }}"
Ok now I understand the following. When the tv is off that variable will never be true since get volume_level will not work.