Light_mode alternative?

Hi

I got help with an automation a while back that looks like this:

service: climate.set_hvac_mode
target:
  entity_id: climate.molnet
data:
  hvac_mode: '{{ trigger.id }}'

I would like to do a similiar trigger based automation for lighting, just to simply my code and how things work, but there is no “light_mode:” option available, if I want the light to be “on” or “off” based on my trigger settings is there any way?

As it is now I “toggle” the lights when each trigger happens, but that is not always correct because sometimes on or a few of those lights have a different state then the others and things get messed up.

I can always just write two automations one for the “on” trigger and one for the “off” trigger, but the question is, can you do it with just one and use trigger_id to decide what is going to happen?

That would be the light state, which is on or off.

You have not given enough information about your trigger but that action may be something like this:

service: "light.turn_{{ trigger.to_state }}"
1 Like

Trigger looks like this:

platform: sun
event: sunrise
offset: 0
id: 'off'

and

platform: sun
event: sunset
offset: '-01:00:00'
id: 'on'

Then it will be:

service: "light.turn_{{ trigger.id }}"
1 Like

What is the alternative for “switches”?

service: "switch.turn_{{ trigger.id }}"

Or for both:

service: "homeassistant.turn_{{ trigger.id }}"
1 Like

Thank you very much!