#what is the actual code of the trigger

1 messages · Page 1 of 1 (latest)

nimble plume
#

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.

dusk glacier
#

Please share the yaml code

nimble plume
#

`platform: state
entity_id:

  • media_player.kirchen_tv
    attribute: volume_level
    `
#

how does this help?

dusk glacier
#

Now I know which trigger variables are available

nimble plume
#

I see.

#

ok

#

Maybe storing last volume level in a variable and then comparing it to current can do the job?

dusk glacier
#

If you use this trigger you will have a variabele increase which will be true in case the volume was increased

nimble plume
#

wow

#

Now I get it.

#

Thanks a lot.

dusk glacier
#

Small fix (forgot the ending quotes)

nimble plume
#

That is_number thing, is it required? Volume level is always a number isn't it?

dusk glacier
#

Not if your device turns on, or is unavailable for a moment

nimble plume
#

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.

dusk glacier
#

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 }}"
nimble plume
#

Ok now I understand the following. When the tv is off that variable will never be true since get volume_level will not work.