What is wrong in these automations:

I have these two automations to set when at home and when not at home, but the switch is always on also if there is none at home. Where i am wrong:

- alias: 'Set non a Casa'
  condition:
    condition: state
    entity_id: input_boolean.mauhome
    state: 'off'
  trigger:
    platform: state
    entity_id: group.all_devices
    to: 'not_home' 
    for:
      minutes: 5
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.mauhome

- alias: 'Set a Casa'
  condition:
    condition: state
    entity_id: input_boolean.mauhome
    state: 'on'
  trigger:
    platform: state
    entity_id: group.all_devices
    to: 'home'  
  action:
     service: homeassistant.turn_on
     entity_id: input_boolean.mauhome

Your conditions are the wrong way round.

Can you correct them for me so i can understand where i am wrong?
Thanks for your support.

The automation that turns the boolean on, only runs if the boolean is already on. The automation that turns the boolean off only runs if the booleans is already off, you need to change your conditions round.

Please will you post the correct code? I am really poor in both HASS and english so i will understand better if i can see the code… It seems what you replied is what i put in automation, but surely i am wrong…

Is this correct:

- alias: 'Set non a Casa'
  condition:
    condition: state
    entity_id: input_boolean.mauhome
    state: 'on'
  trigger:
    platform: state
    entity_id: group.all_devices
    to: 'not_home' 
    for:
      minutes: 5
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.mauhome

- alias: 'Set a Casa'
  condition:
    condition: state
    entity_id: input_boolean.mauhome
    state: 'off'
  trigger:
    platform: state
    entity_id: group.all_devices
    to: 'home'  
  action:
     service: homeassistant.turn_on
     entity_id: input_boolean.mauhome

Yeah, that’s right.

I don’t mind correcting code when I get a second (I’m on my phone so formatting it takes ages), but you also need to slow down a bit and try to work it out once in a while, as evidenced by the fact that you did work it out yourself in the end. You’ll learn much more that way :slight_smile:

1 Like