Automation won't start

In configuration I have this code :

input_boolean:
  kamerlampen:
    name: Kamerlampen
    initial: off

and

automation: !include automations.yaml

When I trigger this with a button it’s state toggles between on and off

In automation I have this code :

- alias: Kamerlampen_aan
  trigger: 
    platform: state
    entity_id: input_boolean.kamerlampen
    to: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: light.schemerlamp_tv
    - delay: '00:00:01'
    - service: homeassistant.turn_on
      entity_id: light.schemerlamp_raam
    - delay: '00:00:01'
    - service: homeassistant.turn_on
      entity_id: light.schemerlamp_kast     
 


 
- alias: Kamerlampen_uit
  trigger: 
    platform: state
    entity_id: input_boolean.kamerlampen
    to: 'off'
  action:
    - service: homeassistant.turn_off
      entity_id: light.schemerlamp_tv
    - delay: '00:00:01'
    - service: homeassistant.turn_off
      entity_id: light.schemerlamp_raam
    - delay: '00:00:01' 
    - service: homeassistant.turn_off
      entity_id: light.schemerlamp_kast  

But nothing happens.
In previous releases it did work (I think)
What do I overlook ?

Are the automations switched on?

1 Like

I did not know I had to do that, but I added this to my configuration (last three lines) ,
but that did not help either

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 53.26086
  longitude: 6.395335
  customize_domain:
    automation:
      initial_state: 'on'

That doesn’t answer the question.

Are the automations switched on? They won’t work if they are switched off.

1 Like

Until now I cannot find any documentation that says that I have to switch automation on, and how to do that.
Are you willing to give me a hint ? I would be very thankfull.

ADD to a view

  • group.all_automations

Just look at the entities page, scroll down to your automations, find the two Kamperlan ones, see if they say on or off.

they are both off. I am still searching for info on this. I cannot remember I had to switch automations on or off. Strange that when you make triggers, you have to activate them on to function properly.
I hope they do not plan to do something like that with switches :wink:

1 Like

There are times when you want to temporarily disable an automation, perhaps because you are testing something and don’t want the automation to interfere, that’s why you have the option to turn it on and off.

Should you wish to combine the two automations into one, here is how you can do it:

- alias: Kamerlampen_aan_uit
  trigger: 
    platform: state
    entity_id: input_boolean.kamerlampen
  action:
    - service_template: 'homeassistant.turn_{{trigger.to_state.state}}'
      entity_id: light.schemerlamp_tv
    - delay: '00:00:01'
    - service_template: 'homeassistant.turn_{{trigger.to_state.state}}'
      entity_id: light.schemerlamp_raam
    - delay: '00:00:01'
    - service_template: 'homeassistant.turn_{{trigger.to_state.state}}'
      entity_id: light.schemerlamp_kast   
1 Like

Hi @123,

Nice to make these shorter and use the trigger!

But why would you add the delay between those actions? I have many automation switch the lights, and simply list them, or maybe even better, turn on a scene which holds these lights, and have some extra settings on color and brightness etc etc.

also, when only using an entity which has its own service, we’re told to best use the dedicated service. In this case light.turn_{{trigger.to_state.state}}

just out of curiosity, why did you add the quotes round the service_templates? Never seen that before, and not needed at all isn’t it?

at least the Op could try:

  action:
    - service_template: >
        light.turn_{{trigger.to_state.state}}
      entity_id: 
        - light.schemerlamp_tv
        - light.schemerlamp_raam
        - light.schemerlamp_kast  
   

or

  action:
    - service_template: >
        light.turn_{{trigger.to_state.state}}
      entity_id: light.schemerlamp_tv, light.schemerlamp_raam, light.schemerlamp_kast  

He didn’t add them, they were in the OP’s original automations.

No, we’re not told to do that at all. Using homeassistant.turn_on/off for consistency is widespread practice.

Single line templates always have quotes around, you just like to make your config messy by making all your templates multiline.

sorry, you got me there…missed that obviously…

widespread practice is seldomly an argument… It would appear that the HA system translates the generic service homeassistant to the respective dedicated services internally. Which takes yet again some processing, and it would be more efficient to call the service directly, if possible. It is in this case, so that’s why I suggested that. They are there for a reason.

well, as always, mileage may vary. Many posts in this community are about quoting and non quoting, and when to or not to, or about mixing quotes of the various availabilities… many errors arise of non working automations and templates.
Doing away with that isn’t making thing messy, it is making things robust en tidy :wink: But in no way necessary.

If you need to be that concerned about a couple of extra cpu cycles here and there you have way more problems than deciding which service to call.

As is homeassistant.turn_on/off :wink:

People could always just follow the accepted practice and style guide for these things, and then they wouldn’t have problems.

https://developers.home-assistant.io/docs/en/documentation_standards.html

(the docs for all components and templates and configurations all follow that style too, so it’s not exactly complicated to match your configuration to it)

great link, wasn’t aware it was there. At least I suggested a valid option :wink:

lol. I use it also. Especially when turning on/off groups, and mixed entities.

Yes you’re completely right about that. It’s just that I try to be as meticulous as possible everywhere, so I don’t miss the smallest bits either. Maybe obsessive. But the moment my browser inspector showed me 0 errors was a big boost in keeping that up.

Anyways, let’s keep inspiring one another . Appreciated!

1 Like

That’s actually the reason I use homeassistant.turn_on everywhere, so my automations and scripts are more versatile. If I suddenly decide to turn on a switch at the same time as a light I can just add the entity of the switch to the list, I don’t have to change the service.

The delay was added, because in previous versions I noticed that when the commands are given to fast to the Rflink gateway, not all commands are executed.

Pleez don’t move from the main subject

yes, the was my approach also. Let me just get back to this one more time, and please don’t take it as trying to get it my way, this really is to share some personal experience.
I did notice unexplained issues of entities not being changed in my setup, mainly items being referenced in scripts which were activated by automations. Very simple but still. After having being advised to do so, I changed to dedicated services, these issues were gone completely.

scripts like:


naar_bed:
  alias: Naar bed
  sequence:
    - service: script.scene_naar_bed
    - service: switch.turn_on
      entity_id: 
        - switch.sw_master_bedroom_cl
        - switch.master_bed_outlet
    - service: home_assistant.turn_off
      entity_id: group.media_player_media
    - service: switch.turn_off
      entity_id:
        - switch.sw_espresso_keuken_cl
        - switch.sw_tv_library_cl
        - switch.sw_netwerk_library_cl
        - switch.sw_audio_gym_cl
        - switch.sw_tv_auditorium_cl
        - switch.sw_netwerk_dorm_cl
        - switch.subwoofer_outlet
    - delay:
        seconds: 5
    - service: switch.turn_off
      entity_id: switch.sw_audio_auditorium_cl
    - delay:
        seconds: 5
    - service: switch.turn_off
      entity_id: switch.sw_netwerk_auditorium_cl

would not run completely when used with the homeassistant service for all entities.

This approach had another advantage, I found out. It is easier to debug when things don’t behave as they should, because it is easier to track down the compromising service for a particular item.

Having said all this, I am a sucker for keeping things as short as possible… SO if you don’t experience any issues, and don’t want to save the last micro second of processor time, I guess there’s no reason to take it the long route…

we’re not really, we’re trying to find the reason your ‘automation won’t start’.

are you still experiencing issues now, or has the change helped you? Have you already turned on your automation, because if not, and that was your last post, it will never start…

and this is not strange, but essential functionality. One has to be able to turn automations on and off… for all sorts of reasons.

There has been a change in the restore state of automations, maybe that’s what you are experiencing. Before it relied on recorder, in now uses storage. So always have an initial_state in all you automations .

Hi Marius, thank you for this extensive answer. I will try to implement it like this.
Still looking for a way to “turn on” the automation however.
I thought my automation script was triggered by toggling the input_boolean

But I still have to do something else apparently. I did not try all the other options here because I went “naar bed” :smile:

Thank you all for your answers. Will try further in the evening (I think)

you can do that several ways:

  • you can even automate turning on automations in an automation :wink: