Automation starts by itself

Hello everyone, I’m here again to disturb …

My code works, but the automation starts by itself without me doing anything.

what can I do? and above all where am I wrong?

CODE 1

  trigger:
  - entity_id: remote.harmony_soggiorno
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template 
    value_template: "{{ states.remote.harmony_soggiorno.attributes.current_activity == 'PowerOff' }}"
  action:
  - service: scene.turn_on
    entity_id: scene.soggiorno_normale

TRIGGER 1

24 agosto 2021
Has been triggered by state of remote.harmony_soggiorno
10:34:37 - 1 ora fa
Has been triggered by state of remote.harmony_soggiorno
9:53:21 - 2 ore fa
Has been triggered by state of remote.harmony_soggiorno
9:48:18 - 2 ore fa
Has been triggered by state of remote.harmony_soggiorno
8:57:41 - 3 ore fa

same problem here:

CODE 2

- alias: GoogleTV taverna off
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template
    value_template: "{{ states.remote.harmony_taverna.attributes.current_activity == 'PowerOff' }}"
  action:
  - service: scene.turn_on
    entity_id: scene.taverna_normale
  - delay: 00:01:00
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_mediabase
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_games

TRIGGER 2

24 agosto 2021
Has been triggered by state of remote.harmony_taverna
8:11:06 - 4 ore fa

Here

CODE 3

- alias: "Selezione Switch OFF"
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template
    value_template: >
      {{ not state_attr('remote.harmony_taverna', 'current_activity') in [ 'Project GoogleTV', 'Project PC', 'Watch PC', 'Projector', 'Television', 'Watch GoogleTV', 'Watch TV', 'Play Xbox 360', 'Play Wii', 'Project Wii', 'Project Xbox 360', 'Play Retro Console' ] }}
  - condition: template
    value_template: "{{ states.remote.harmony_taverna.attributes.current_activity == 'PowerOff' }}"
  action:
  - delay: 00:01:30
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_mediabase
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_games

TRIGGER 3:

24 agosto 2021
Has been triggered by state of remote.harmony_taverna
8:11:06 - 4 ore fa

and here:

CODE 4:

- alias: "Selezione Switch ON"
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    from: 'PowerOff'
  action:
    choose:
      - alias: "Attivita Taverna MEDIA"
        conditions:
          - condition: template
            value_template: "{{ state_attr('remote.harmony_taverna', 'current_activity') in [ 'Project GoogleTV', 'Project PC', 'Watch PC', 'Projector', 'Television', 'Watch GoogleTV', 'Watch TV' ] }}"
        sequence:
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_mediabase
      - alias: "Attivita Taverna GAMES"
        conditions:
          - condition: template
            value_template: "{{ state_attr('remote.harmony_taverna', 'current_activity') in [ 'Play Xbox 360', 'Play Wii', 'Project Wii', 'Project Xbox 360', 'Play Retro Console' ] }}"
        sequence:
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_mediabase
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_games

TRIGGER 4:

24 agosto 2021
Has been triggered by state of remote.harmony_taverna
8:10:27 - 4 ore fa

Probably triggered because state changed from unavailable to PowerOff. Try adding from and to in the trigger to specify the previous state and the next state.

I assume it’s because there is an update from the device, but with the same state as before, that triggers your automations.

If that’s the case this condition should stop it:

  condition:
  - "{{ trigger.from_state.state != trigger.to_state.state}}"

I thought about this as well, but I was not sure whether the trigger state will be the state of the attribute or the state of the entity?

Oh. I missed that it was an attribute state trigger. Hmm not sure. I think I remember being stymied by that before as it did not return the attribute state.

I can’t test right now, but I think this should work then

- "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"

As the attributes are included in the state object as far as I can see in the docs

Remove state from both sides of the equation.

Was this aimed at me or both of us. Because I do have this condition in my config:

"{{ trigger.from_state.state != trigger.to_state.state}}"

Sorry, I thought I had replied directly to Burningstone but there’s nothing in the message showing that. I suggested that Burningstone’s template be changed to:

- "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"

FWIW, if I was experiencing this problem, I would add persistent_notifications to report the value of current_activity for from_state to get a better idea of what’s happening when it triggers “unexpectedly”. Alternatively, add an id to the automation so that a trace is generated when it triggers. Examine the trace to determine the value of from_state.attributes.current_activity.

Thanks, fixed it.

I think I remember having the same issues with my harmony remote. It sends the same activity (PowerOff) again and again when it is off.

Hello everyone
Unfortunately none of the solutions proposed and also other attempts made by me work …
do you have any other ideas?

Place my latest code (but I swear I’ve made several attempts).
Thanks

- alias: GoogleTV soggiorno off
  trigger:
  - entity_id: remote.harmony_soggiorno
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"
  - condition: template
    value_template: "{{ trigger.from_state.state != unavailable }}"
  action:
  - service: scene.turn_on
    entity_id: scene.soggiorno_normale

Activated by

Has been triggered by state of remote.harmony_soggiorno
- alias: GoogleTV taverna off
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"
  - condition: template
    value_template: "{{ trigger.from_state.state != unavailable }}"
  action:
  - service: scene.turn_on
    entity_id: scene.taverna_normale
  - delay: 00:01:00
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_mediabase
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_games
- alias: Selezione Switch ON
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    from: 'PowerOff'
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"
  - condition: template
    value_template: "{{ trigger.to_state.state != unavailable }}"
  action:
    choose:
      - alias: "Attivita Taverna MEDIA"
        conditions:
          - condition: template
            value_template: "{{ state_attr('remote.harmony_taverna', 'current_activity') in [ 'Project GoogleTV', 'Project PC', 'Watch PC', 'Projector', 'Television', 'Watch GoogleTV', 'Watch TV' ] }}"
        sequence:
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_mediabase
      - alias: "Attivita Taverna GAMES"
        conditions:
          - condition: template
            value_template: "{{ state_attr('remote.harmony_taverna', 'current_activity') in [ 'Play Xbox 360', 'Play Wii', 'Project Wii', 'Project Xbox 360', 'Play Retro Console' ] }}"
        sequence:
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_mediabase
          - service: switch.turn_on
            entity_id: switch.media_taverna_mss120b_outlet_games

- alias: Selezione Switch OFF
  trigger:
  - entity_id: remote.harmony_taverna
    platform: state
    attribute: current_activity
    to: 'PowerOff'
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes.current_activity != trigger.to_state.attributes.current_activity }}"
  - condition: template
    value_template: "{{ trigger.from_state.state != unavailable }}"
  - condition: template
    value_template: >
      {{ not state_attr('remote.harmony_taverna', 'current_activity') in [ 'Project GoogleTV', 'Project PC', 'Watch PC', 'Projector', 'Television', 'Watch GoogleTV', 'Watch TV', 'Play Xbox 360', 'Play Wii', 'Project Wii', 'Project Xbox 360', 'Play Retro Console' ] }}
  action:
  - delay: 00:01:30
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_mediabase
  - service: switch.turn_off
    entity_id: switch.media_taverna_mss120b_outlet_games

All three activated by

Has been triggered by state of remote.harmony_taverna

You have to wrap the word unavailable in quotes otherwise it’s handled as the name of a (non-existent) variable.

You should add an id to the automation and then Home Assistant will generate a trace each time the automation is triggered. Examining the trace will reveal the previous value of the current_activity attribute.

- alias: GoogleTV soggiorno off
  id: 'use_something_unique_here'
  trigger: