Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 107711

Conditional action in an automation

$
0
0

I’m struggling to come up with a way to have one button toggle between different states of the light. I’m trying to get it to work in the following way:

  1. The light is off.
  2. First button press toggles the light on, sets the brightness to 50/256 and temperature to 2200 K
  3. Second button press increases the brightness to 150 and changes temperature to 2800 K
  4. Third button press increased the brightness all the way up to 255 and temperature to 3200 K
  5. Fourth button press turns the lift off, so moving back to step 1.

I don’t want to write 4 different automations for this, each with each own condition. I’d like to have one automation. I’m trying this approach (for now only two states):

alias: ...
trigger:
  - ... truncated for brevity ...
condition: []
action:
{% if is_state('light.lamp', 'off') %}
  - action: light.turn_on
    data:
      entity_id: light.lamp
      brightness: 50
{% else %}
  - action: light.turn_off
    data:
      entity_id: light.lamp
{% endif %}
mode: single

The syntax isn’t valid though. I’m struggling to come up with a way to have a conditional item in the actions array that would depend on the state. Tried to find a way to do that in Jinja docs, but to no avail. I’d appreciate any pointers. Thanks!

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 107711

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>