Automations turning off randomly

Hi Everyone,

I have one problem that I’m unable to resolve. My automation’s keep turning off and sometimes not triggering. Noticed mostly with automation that are related to lights. I use motion detectors to catch movement.

m1_logbook m2 logbook

As you can see in the logbook I get automation turned off, but in UI it’s on. Works again if I manually turn off and on the automation for some time, but again starts to be messed up.

I can’t really pin-point what is causing this and would appreciate any idea. I mostly use UI to do create my automation’s.

Thanks Everyone!

Did you restart HA or reload automations when it was turned off?
When you restart HA or reload automations, all automations will be turned off and then on again.
But you’ll only see the turn off in the logbook.

Hi, no… It’s up for over a day. I tried adding the following line to automations:
initial_state: ‘on’
But this didn’t help :confused:

Any errors in the logs? Do you have any auzomatioms that turn off other automations? Can you pleade share the code of this automation.

Hi,

no, can’t really see any error relating to this.

As far as I know there is no automations that turn off other automations. Just went trough all of them…

here is one:

id: ‘160354xxxxxxxx
alias: dnevna_on_motion
initial_state: ‘on’
description: ‘’
trigger:

  • type: motion
    platform: device
    device_id: 6141e057158a11ebb9xxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
    condition:
  • type: is_illuminance
    condition: device
    device_id: 6141e057158a11ebxxxxxxxxxxx
    entity_id: sensor.lightlevel_4
    domain: sensor
    below: 18
    action:
  • service: script.svijetla_dnevna_turn_on
    data: {}
    mode: single
    max: 30

and this one as well:

alias: Dnevna_Off_Motion
description: ‘’
trigger:

  • type: motion
    platform: device
    device_id: 69a795xxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 64a90b8axxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 18f6ef5289xxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 83cf480315f7xxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
    condition:
  • condition: and
    conditions:
    • type: is_no_motion
      condition: device
      device_id: 6141e057158a11exxxxxxxxxxxx
      entity_id: binary_sensor.motion_dnevna
      domain: binary_sensor
    • type: is_no_motion
      condition: device
      device_id: 94fbd8a817e111xxxxxxxxxxx
      entity_id: binary_sensor.presence_34
      domain: binary_sensor
      action:
  • service: script.svijetla_dnevna_turn_off
    data: {}
    mode: single

and this one:

alias: Spavaca_off_motion
description: ‘’
trigger:

  • type: motion
    platform: device
    device_id: 6141e057158a11xxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 18f6ef5289cexxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 64a90b8a15831xxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 69a795a115xxxxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  • type: motion
    platform: device
    device_id: 94fbd8a817exxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
    condition:
  • type: is_no_motion
    condition: device
    device_id: 83cf480315f711ebxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
    action:
  • type: turn_off
    device_id: 1bbd6d982exxxxxxxxxxxxxxxxxxxx
    entity_id: light.spavaca_ikea_color
    domain: light
  • type: turn_off
    device_id: 41027a7669d729xxxxxxxxxxxxxx
    entity_id: light.192_168_31_151
    domain: light
    mode: single

Please post your automation using “</>” so it is formatted correctly.
I don’t see any action in your automation:

alias: Kid Bathroom Light Motion On
description: Turn on light with motion
trigger:
  - entity_id: binary_sensor.bathroom_kid_motion
    from: 'off'
    platform: state
    to: 'on'
condition:
  - condition: time
    after: '05:00:00'
    before: '21:30:00'
action:
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: switch.shelly_shsw_pm_xxxxxx
    domain: switch
mode: single
alias: Kid Bathroom Light Auto Off
description: Turn off light after no motion
trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_kid_motion
    from: 'on'
    to: 'off'
    for: '00:10:00'
condition: []
action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: switch.shelly_shsw_pm_xxxxxx1
    domain: switch
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: switch.shelly_shsw_pm_xxxxxx2
    domain: switch
mode: single

Sorry, will do from now on.
Automations have “actions:” in the last rows.

sorry missed it hidden and indented above the bullet

Please repost, so it is easier to read

Please repost the automation correctly formatted as Glenn pointed out.
One thing I noted already is that you put max: 30 for an automation in mode: single, this makes no sense, this is only for parallel or queued mode.

Ok, I re-wrote some of this automation, and turned every other automation off from the GUI. So now only this is running and I can see this in the logbook:

Automations that are currently running on the RPI (rest are disabled over GUI).

I still have the same behavior of them not working or triggering (mostly for lights off…).

id: 'xxxxxxxxxxx'
  alias: Dnevna_Off_Motion
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
  condition:
  - condition: and
    conditions:
    - type: is_no_motion
      condition: device
      device_id: xxxxxxxxxxx
      entity_id: binary_sensor.motion_dnevna
      domain: binary_sensor
    - type: is_no_motion
      condition: device
      device_id: xxxxxxxxxxx
      entity_id: binary_sensor.presence_34
      domain: binary_sensor
  action:
  - service: script.svijetla_dnevna_turn_off
    data: {}
  mode: single
id: 'xxxxxxxxxxx'
  alias: dnevna_off_motion_2
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition:
  - condition: device
    type: is_on
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_prozora_1s_white
    domain: light
  - type: is_no_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
  action:
  - service: script.svijetla_dnevna_turn_off
    data: {}
  mode: single

id: 'xxxxxxxxxxx'
  alias: dnevna_on_motion
  initial_state: 'on'
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
  condition:
  - type: is_illuminance
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: sensor.lightlevel_4
    domain: sensor
    below: 18
  action:
  - service: script.svijetla_dnevna_turn_on
    data: {}
  mode: single
id: 'xxxxxxxxxxx'
  alias: Hodnik_turn_off_motion
  initial_state: 'on'
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
  condition: []
  action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.yeelight_hodnik
    domain: light
  mode: single

 id: 'xxxxxxxxxxx'
  alias: Hodnik_turn_on_motion
  initial_state: 'on'
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  condition: []
  action:
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.yeelight_hodnik
    domain: light
  mode: single

 id: 'xxxxxxxxxxx'
  alias: Ikea_tradfri_krevet_All_Off
  description: ''
  trigger:
  - device_id: xxxxxxxxxxx
    domain: deconz
    platform: device
    type: remote_button_long_press
    subtype: turn_off
  condition: []
  action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.dimmable_light_2
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.dnevna_do_vrata_1s
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_prozora_1s_white
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_vrata
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.hektar
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.dnevna_do_prozora
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.yeelight_hodnik
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.spavaca_ikea_color
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: switch.outlet_dnevna
    domain: switch
  - scene: scene.miio_outlet_test_off
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.192_168_31_151
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: switch.outlet_kuhinja
    domain: switch
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: switch.outlet_fado
    domain: switch
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kupaona_ikea_800lm
    domain: light
  mode: single
 id: '1607038943757'
  alias: Kuhinja_off_motion
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
  condition:
  - type: is_no_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_prozora_1s_white
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_vrata
    domain: light
  mode: single

id: 'xxxxxxxxxxx'
  alias: kuhinja_off_motion_2
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition:
  - condition: device
    type: is_on
    device_id: xxxxxxxxxxx
    entity_id: light.dnevna_do_prozora
    domain: light
  - type: is_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
  - type: is_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
  action:
  - service: script.kuhinja_off_lights
    data: {}
  mode: single
 id: 'xxxxxxxxxxx'
  alias: kuhinja_on_motion
  initial_state: 'on'
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  condition:
  - type: is_illuminance
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: sensor.lightlevel_7
    domain: sensor
    below: 18
  action:
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_prozora_1s_white
    domain: light
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.kuhinja_do_vrata
    domain: light
  mode: single

id: 'xxxxxxxxxxx'
  alias: motion_turn_off_kupaona
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
    for:
      hours: 0
      minutes: 5
      seconds: 0
  condition:
  - type: is_humidity
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: sensor.humidity_18
    domain: sensor
    below: 85
    above: 5
  action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.kupaona_ikea_800lm
    domain: light
  initial_state: 'on'
  mode: restart
- id: '1603735171572'
  alias: motion_turn_on_kupaona
  description: ''
  trigger:
  - platform: device
    domain: binary_sensor
    entity_id: binary_sensor.presence_3
    device_id: xxxxxxxxxxx
    type: motion
  condition: []
  action:
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.kupaona_ikea_800lm
    domain: light
    flash: short
  mode: single

 id: 'xxxxxxxxxxx'
  alias: Spavaca_off_motion
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_dnevna
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_31
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_3
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_8
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
  condition:
  - type: is_no_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
  action:
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.spavaca_ikea_color
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxx
    entity_id: light.192_168_31_151
    domain: light
  mode: single

id: 'xxxxxxxxxxx'
  alias: spavaca_off_motion_2
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition:
  - type: is_motion
    condition: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.presence_34
    domain: binary_sensor
  action:
  - service: script.spavaca_off_light
    data: {}
  mode: single
id: 'xxxxxxxxxxx'
  alias: spavaca_on_motion
  initial_state: 'on'
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxx
    entity_id: binary_sensor.motion_sensor_spavaca
    domain: binary_sensor
  condition: []
  action:
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.spavaca_ikea_color
    domain: light
  - type: turn_on
    device_id: xxxxxxxxxxx
    entity_id: light.192_168_31_151
    domain: light
  mode: single

I don’t see any states in your triggers or conditions.
I see ‘sometimes’ you have a time frame (for) but you don’t specify on for or off for.
There might be ‘defaults’ for some types, but I have never used it that way and it kinda makes it confusing as to what you are trying to do. Look at my example above and put in the states and try.

Well, I’m not a developer or in coding, so I do this by logic. To short it out: I use motion sensors of other rooms to trigger light turn off in other rooms. Worked well in the beginning.

Conditions are not mandatory, right? I will now try and add time to every automation.

As I mention before, this was all done over GUI.

I see that you are calling scripts in your actions, what are these scripts doing? Do they turn off automations? Do you see nothing under Configuration -> Logs?
Can you turn off all except for one automation and test again?

No, simple stuff. Here is eveything from my scritps.yaml:

svijetla_dnevna_turn_off:
  alias: Svijetla_Dnevna_Turn_Off
  sequence:
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.dnevna_do_prozora
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.dnevna_do_vrata_1s
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.hektar
    domain: light
  mode: single
svijetla_dnevna_turn_on:
  alias: Svijetla_Dnevna_Turn_On
  sequence:
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.dnevna_do_prozora
    domain: light
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.dnevna_do_vrata_1s
    domain: light
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.hektar
    domain: light
  mode: single
spavaca_purple_mode:
  alias: Spavaca_Purple_Mode
  sequence:
  - scene: scene.spavaca_ikea_ljubicast
  mode: single
spavaca_off_light:
  alias: Spavaca_Off_light
  sequence:
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.192_168_31_151
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.spavaca_ikea_color
    domain: light
  mode: single
kuhinja_off_lights:
  alias: kuhinja_off_lights
  sequence:
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.kuhinja_do_prozora_1s_white
    domain: light
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxx
    entity_id: light.kuhinja_do_vrata
    domain: light
  mode: single

this is everything from the log since over 24hours:

Spavaca_off_motion: Already running

8:10:25 PM – Automation (WARNING) - message first occurred at 8:46:11 AM and shows up 13 times

Update of media_player.samsung_tv_dnevna is taking over 10 seconds

7:14:03 PM – helpers/entity.py (WARNING) - message first occurred at December 3, 2020, 11:20:19 PM and shows up 3 times

Updating samsungtv media_player took longer than the scheduled update interval 0:00:10

7:14:03 PM – Media player (WARNING) - message first occurred at December 3, 2020, 11:20:19 PM and shows up 4 times

Kuhinja_off_motion: Already running

10:50:06 AM – Automation (WARNING) - message first occurred at 8:42:41 AM and shows up 3 times

Too many retries

12:44:30 AM – /usr/local/lib/python3.8/site-packages/pyatmo/auth.py (ERROR) - message first occurred at 12:43:30 AM and shows up 2 times

Unable to turn the bulb on: A socket error occurred when sending the command.

12:32:37 AM – Yeelight (ERROR)

Updating device list from legacy took longer than the scheduled scan interval 0:00:12

December 3, 2020, 11:46:19 PM – Device tracker (WARNING)

emphasized text

Several ‘distress calls’ in that log …

just a couple of things I see what may be wrong,
what is device_id:?
what service call are you using? - type: turn_off , don’t know what that is, maybe change that to

 action:
    - service: light.turn_off
      target:
        entity_id: light.dnevna_do_vrata_1s