Light switch automation when pressing button and sun below horizon


I’m using a blueprint so automate the double press of the ON button on my inovelli switch. Now i wanted to add that when the sun is below horizon the color temp of the light bulb is set.

here is what i got:

- id: '1635288344964'
  alias: Light Louis On/Off
  description: ''
    path: jerelabs/zwave-js-inovelli-lzw31-sn-red-series-dimmer.yaml
      inovelli_switch: d4dcdd870e75a7b85d619c0908b8ddfb
      - service: light.turn_on
          entity_id: light.ampoule_a_louis
          color_temp: >-
            {% if is_state('sun.sun','below_horizon') %}
              color_temp: 461
            {% else %}
              color_temp: '{{ range(40, 600) | random }}'
      - service: light.turn_off
          entity_id: light.ampoule_a_louis
        data: {}

But the color_temp is not set. I have search in the forum and documentation and didn’t find anything to help me out. What is the correct format to add an IF statement ?


          color_temp: >-
            {% if is_state('sun.sun','below_horizon') %}
            {% else %}
              {{ range(40, 600) | random }}
            {% endif %}
1 Like

Well that doesn’t work either. It doesn’t change the light bulb temperature color. They are LIFX light bulbs, and i can adjust them manually. So it should work, i should be able to set the color_temp when i open the light in that automation.

Then something else is wrong in your automation.

I tested the suggested code with one of my LIFX bulbs using Developer Tools > Services and every time I clicked Call Service the light’s color changed.

Well, i got it to work. Newbie error, i forgot to do a reload of automation, since i had modified the automation.yaml file.


Well, got it to work. Thanks.