Light switch automation when pressing button and sun below horizon

Hi,

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: ''
  use_blueprint:
    path: jerelabs/zwave-js-inovelli-lzw31-sn-red-series-dimmer.yaml
    input:
      inovelli_switch: d4dcdd870e75a7b85d619c0908b8ddfb
      button_a2:
      - service: light.turn_on
        target:
          entity_id: light.ampoule_a_louis
        data:
          color_temp: >-
            {% if is_state('sun.sun','below_horizon') %}
              color_temp: 461
            {% else %}
              color_temp: '{{ range(40, 600) | random }}'
      button_b2:
      - service: light.turn_off
        target:
          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 ?

Thanks

        data:
          color_temp: >-
            {% if is_state('sun.sun','below_horizon') %}
              461
            {% 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.

Sorry…

Well, got it to work. Thanks.