Automations.yaml

Hi

I’m trying to make my Flic buttons (integrated as input boolean) behave like buttons not toggle switches. I have the following in my automation.yaml, but only the last entry actually behaves correctly.

Any ideas?

  - alias: "Flic2 singleclick act as button"
  trigger:
    platform: state
    entity_id: input_boolean.flic2_singleclick
  action:
    service: >
      {% if states.input_boolean.state == "off" %}
      input_boolean.turn_on
      {% else %}
      input_boolean.turn_off
      {% endif %}
    data:
      entity_id: input_boolean.flic2_singleclick

  - alias: "Flic3 singleclick act as button"
  trigger:
    platform: state
    entity_id: input_boolean.flic3_singleclick
  action:
    service: >
      {% if input_boolean.flic3_singleclick == "off" %}
      input_boolean.turn_on
      {% else %}
      input_boolean.turn_off
      {% endif %}
    data:
      entity_id: input_boolean.flic3_singleclick

  - alias: "Flic2 doubleclick act as button"
  trigger:
    platform: state
    entity_id: input_boolean.flic3_doubleclick
  action:
    service: >
      {% if states.input_boolean.state == "off" %}
      input_boolean.turn_on
      {% else %}
      input_boolean.turn_off
      {% endif %}
    data:
      entity_id: input_boolean.flic3_doubleclick 

Did you check the list of services?

There is an input_boolean.toggle service after all.

2 Likes

I want them to behave like a momentary button rather than a toggle switch.

Your indentation is out. Should look like this (first one only shown, rest should be the same):

  - alias: "Flic2 singleclick act as button"
    trigger:
      - platform: state
        entity_id: input_boolean.flic2_singleclick
    action:
      - service: >
          {% if states.input_boolean.state == "off" %} !!!! THIS WON'T WORK
            input_boolean.turn_on
          {% else %}
            input_boolean.turn_off
          {% endif %}
        data:
          entity_id: input_boolean.flic2_singleclick

The - denotes the start of a list, then all the elements of that list need to be similarly indented — your alias, trigger and action.

Where there’s only one element to the list, as under your trigger and action, it’s not strictly necessary to include the -, but it’s a good habit to get into, so I’ve done it here. When you then add other triggers, it looks like this:

    trigger:
      - platform: state
        entity_id: input_boolean.flic2_singleclick
      - platform: time
        at: "12:34:56"

In your original file, you created a trigger and action and then overwrote them twice, with the last one being the final version, because they weren’t part of the list under the alias due to the incorrect indentation.

I’ve also highlighted a broken line. You have different versions of the test in the three automations:

{% if states.input_boolean.state == "off" %}
{% if input_boolean.flic3_singleclick == "off" %}
{% if states.input_boolean.state == "off" %}

and none of these will work. If you’re looking at the flic3 entity, you want:

{% if states('input_boolean.flic3_singleclick') == 'off' %}
1 Like

Thank you!
Works a treat now. Much appreciated.

See my update: your tests are wrong. The automations might load, but they won’t work as you intend. See the warning box in this section.

1 Like