How to trigger automation by state without to or from

I like to use a input switch to control my mower. In order to have one automation, I like to trigger that automation when the switch changes, no matter to or from what state. How do I do this (in one automation)? By the way, I ask this also because it seems not to work when I add multiple triggers for the same device.

I like to create this automation:

mower

Don’t supply a to: or from: state and the state trigger will trigger on all changes of sate (including attributes).Then use choose actions to progress through your flow chart.

Trigger variables may be of some use in your choose conditions too.

You didn’t mention what kind of integration you are using for your mower or the names of the entities involved … so I made them up to provide you with an example. If you supply the missing information, I can update the automation with the correct entities and service calls.

- alias: Example Mower Control
  id: example_mower_control
  trigger:
  - platform: state
    entity_id: switch.mower
  action:
  - choose:
    - conditions:
      - "{{ trigger.to_state.state == 'on'}}"
      - "{{ is_state('binary_sensor.mower_docked', 'on' }}"
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.mow
    - conditions:
      - "{{ trigger.to_state.state == 'off'}}"
      - "{{ is_state('binary_sensor.mower_docked', 'off' }}"
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.return

Thank you for your answer. I have thought about that too, but is seems mandatory to add a data block to the trigger. here is my code. As you can see, an error is shown that blocks the script from beĂŻng saved (YAML editing mode).

@123 was guessing the syntax as you hadn’t specified the integration. Now we know, here is the documentation you need:

So you need to reformat your code like this:

- service: indego.command
  data:
    command: mow

Yes, now it work! Thanks

Seriously? What you marked as the Solution has nothing to do with the questions in your first post (which concerned itself with multiple triggers, and from and to options, not with how to properly call a service).

Seems like you don’t understand Home Assistant’s terminology. That’s a data option for a service call, not a trigger.

:kissing_heart: I stole your Solution! :stuck_out_tongue:

Seriously, @pdwonline, please mark @123’s post as the solution to your question rather than mine. Mine was just a follow-on correction on a minor point that emerged once you’d given us the info we needed.

No worries; you stole nothing, it’s the topic’s author who has misunderstood the purpose of the Solution tag. The original question was:

The alleged answer to this question is now officially:

? :thinking: ? Not exactly the answer to the original question (but a correction to a subsequently posted automation).

Fact is that tom_I answered the original question.

1 Like

my bad, sorry
marked the solution correctly now!

1 Like