Help with basic automation

This is quite embarrassing, but I can not get my basic “Turn on light when door opens” automation. I have Telldus door switch and ONOFF switch which I can read and control from dashboard. But the automation does not work. IT is defined in the Automation configuration.

Can anybody point me in the rigth direction?

 - id: '1536954990810'
  alias: Loftbod på
  trigger:
  - entity_id: switch.loftbod_dr
    from: 'Av'
    platform: state
    to: 'På'
  condition: []
  action:
  - condition: state
    entity_id: switch.loftbod_lys
    state: 'På'
    
- id: '1536955071235'
  alias: Loftbod av
  trigger:
  - entity_id: switch.loftbod_dr
    from: 'På'
    platform: state
    to: 'Av'
  condition: []
  action:
  - condition: state
    entity_id: switch.loftbod_lys
    state: 'Av'

  • You might want to use ‘on’ and ‘off’ for the state instead of Av and På
  • It looks like you have a condition defined, but not an action
  • It’s impossible to judge if your spacing is correct unless you format your code properly - for help with that please see the blue box at the top.

Here is an example from my automations:

- alias: 'Plug2 off turns etekcity_0315_4 on'
  trigger:
    platform: state
    entity_id: switch.plug2
    to: 'off'
  condition: 
    - condition: state
      entity_id: device_tracker.wgs_sgs7
      state: 'home'
  action:
    - delay: '00:03:00'
    - service: switch.turn_on
      entity_id: switch.etekcity_0315_4

Skip the condition section completely if you don’t need one.

Excellent. Did some modifications inspired by your config, and now it works :slight_smile:

Thx

- id: '1536954990810'
  alias: Loftbod på
  trigger:
    platform: state
    entity_id: switch.loftbod_dr
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.loftbod_lys

- id: '1536955071235'
  alias: Loftbod av
  trigger:
    platform: state
    entity_id: switch.loftbod_dr
    to: 'off'
  action:
    service: switch.turn_off
    entity_id: switch.loftbod_lys
1 Like

Great sense of achievement when one gets even just these little thing to work - isn’t it?
For the benefit of the other forum participants, would you mind marking the topic as ‘Solved’?

Yes. Nice for us newbees.
A followup question: is it possible to implement AND/OR in this code?
“If switch1 OR switch2, then switch3”

And could it be better to implement both on and off in the same automation?

all triggers are ‘or’ by default and can’t be changed (I don’t think…).

conditions can be either ‘and’, ‘or’ or a combination of the two.

and usually when you mark something as ‘solved’ you normally give the ‘solved’ attribution to the person who helped you solve the problem, not to yourself. otherwise you wouldn’t have come here to ask for help. :wink:

This should work:

- id: '1536954990810'
  alias: Loftbod på
  trigger:
    platform: state
    entity_id: switch.loftbod_dr, switch.loftbod_2nd
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.loftbod_lys

Although I prefer to do it this way:

- id: '1536954990810'
  alias: Loftbod på
  trigger:
    - platform: state
      entity_id: switch.loftbod_dr
      to: 'on'
    - platform: state
      entity_id: switch.loftbod_2nd
      to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.loftbod_lys

You can change the triggers to be ‘and’ as well as the conditions to be ‘or’.
Take a look here:

Yeah, sorry, I’m not seeing it…

The link you have above is for conditions (which can, in fact, be defined as either ‘or’ or ‘and’).

It doesn’t say anything about triggers being able to be ‘and’.

The trigger docs only reference being ‘or’.

" MULTIPLE TRIGGERS

… Whenever one of the triggers fires, your rule is executed."

If I’m missing something, please, give me more specific info.

The usage for triggers is the same as for conditions and the usage for ‘and’ is the same as for ‘or’.

The only difference is that for trigger the assumption is ‘or’ if nothing else is specified and for conditions it’s ‘and’ if nothing is specified.

Is that specified in the docs anywhere? Because the link you supplied doesn’t say it’s relevant to triggers, only conditions.

If that’s the case then that seems to be a pretty big oversight and I’m positive I’m not the only one with that misconception.

EDIT:

and I’m honestly not sure how that would work in practice.

When is it that you would have two triggers happening at EXACTLY the same time? If they don’t need to happen at the same time then how is a trigger distinguishable from a condition?