[SOLVED] State Automation doesn't run

I have an automation that is designed to turn everything off if noone is home, however for whatever reason it doesn’t trigger.

This is weird though as the automation that is supposed to trigger when someone comes back home appears to work fine.

OIt look perfectly fine to me, however hoping a fresh pair of eyes can help me diagnose why its not triggering.

automations.yaml

 #Go to Auto Away mode if noone is in
 - alias: 'Away Mode'
   initial_state: true
   trigger:
     platform: state
     entity_id: binary_sensor.people_home
     from: 'on'
     to: 'off'
     for:
       minutes: 10
   action:
     - service: script.away_mode 
     - service: notify.all
       data:
         message: 'Auto Away Mode activated'
     - service: script.audio_notify
       data_template:
         tts_msg: "Auto Away mode activated"

scripts.yaml

   ## Away mode
   away_mode:
     sequence:
       - service: switch.turn_off
         data:
           entity_id: switch.bathroom_tv, switch.charlottes_bedroom_light, switch.charlottes_tv_left, switch.charlottes_tv_right, switch.downstairs_bathroom_light, switch.games_consoles, switch.home_audio_1, switch.home_audio_1a, switch.home_audio_1b, switch.home_audio_1c, switch.home_audio_1d, switch.home_audio_2, switch.home_audio_2a, switch.home_audio_2b, switch.home_audio_2c, switch.home_audio_2d, switch.home_office_tv_left, switch.home_office_tv_right, switch.katies_tv_left, switch.katies_tv_right, switch.kitchen_light, switch.kitchen_tv_left, switch.kitchen_tv_right, switch.living_room_light, switch.living_room_tv_left, switch.living_room_tv_right, switch.master_bedroom_light, switch_master_bedroom_tv_b, switch.master_bedroom_tv_c, switch.master_bedroom_tv_d, switch.media_equipment_cupboard, switch.projector_and_screen, switch.utility_room_light, switch.xboxone
       - service: light.turn_off
         data:
           entity_id: light.flux_living_room_tv
       - service: nest.set_away_mode
         data:
           away_mode: away
       - service: climate.set_operation_mode
         data:
           entity_id: climate.entryway
           operation_mode: 'eco'

configuration.yaml

# Binary Sensors
binary_sensor:
  - platform: template
    sensors:
      people_home:
        friendly_name: 'People Home'
        device_class: presence
        value_template: >
          {{ is_state('person.name1', 'home') or
             is_state('person.name2', 'home') or
             is_state('person.name3', 'home') or
             is_state('person.name4', 'home') }}

I have also checked the state history of the binary sensor and it is changing, not so much over last 24 hours as the weekend but i have seen it changing.

people-home-state-change

Any help greatly appreciated.

1 Like

It appears your ‘people_home’ sensors states are not ‘on’ and ‘off’, but ‘home’ and (presumably) ‘not_home’

Thanks for the reply @anon43302295 but if you look at the screenshot below it looks like on/off which i thought was the default states for a binary sensor.

Though there has been that many updates of HASS.IO over the last few months who knows

Though you are correct the screenshot i took does say Home ???

Srange

If you set a device class it changes the default on off states to the states listed in the docs

Ok thanks @EGO01 so instead of on/off we use the state based on the class instead.

I don’t think so for automation state but it’s worth a try changing it. It only changes how the sensor appears in the ui state. Hence your screen shot says home or away for the state

Does the automation trigger if you do it manually?

@EGO01 If I manually trigger it nothing happens

Do the scripts work if you trigger them manually?

Confirm automation.away_mode is on. It may indeed be on but it doesn’t hurt to check.

@123 the automation is indeed on, i also took stock of the advice given thus far and i rewrote the automation to see where it may be going wrong … however again it doesnt seem to do anything.

#Go to Auto Away mode if noone is in
- alias: 'Away Mode'
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.people_home
    from: 'on'
    to: 'off'
    for:
      minutes: 10
  action:
    - service: switch.turn_off
      data:
        entity_id: switch.bathroom_tv, switch.charlottes_bedroom_light, switch.charlottes_tv_left, switch.charlottes_tv_right, switch.downstairs_bathroom_light, switch.games_consoles, switch.home_audio_1, switch.home_audio_1a, switch.home_audio_1b, switch.home_audio_1c, switch.home_audio_1d, switch.home_audio_2, switch.home_audio_2a, switch.home_audio_2b, switch.home_audio_2c, switch.home_audio_2d, switch.home_office_tv_left, switch.home_office_tv_right, switch.katies_tv_left, switch.katies_tv_right, switch.kitchen_light, switch.kitchen_tv_left, switch.kitchen_tv_right, switch.living_room_light, switch.living_room_tv_left, switch.living_room_tv_right, switch.master_bedroom_light, switch_master_bedroom_tv_b, switch.master_bedroom_tv_c, switch.master_bedroom_tv_d, switch.media_equipment_cupboard, switch.projector_and_screen, switch.utility_room_light, switch.xboxone, light.flux_living_room_tv
    - service: nest.set_away_mode
      data:
        away_mode: away
    - service: climate.set_operation_mode
      entity_id: climate.entryway
      data:
        operation_mode: 'eco'      
    - service: notify.all
      data:
        message: 'Auto Away Mode activated'
    - service: script.audio_notify
      data_template:
        tts_msg: "Auto Away mode activated"

Now i know for a fact the notify services work perfectly as they are in place on every single one of my automations, so surely even if the switch.turn_off function wasnting working as expected i should still get the notification.

Its all very strange.

What does the log say when you manually trigger the automation?

OK, automation is on. When you execute an automation manually (from the Services page), its action and condition (if any) are skipped and only the action section is executed. That means when you manually run automation.away_mode it should turn off several switches, set the climate operation, etc.

When you run the automation manually, are you seeing its action section executed? If not, then something is fundamentally wrong … and should be reporting it in the system log.

i get this error in the logs

## Log Details (ERROR)

Mon Jul 08 2019 13:41:58 GMT+0100 (British Summer Time)

Error while executing automation automation.away_mode. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

That’s a useful clue. The last item in that long list is light.flux_living_room_tv whereas all others are switches. Change the service from:

switch.turn_off

to:

homeassistant.turn_off

I think the problem lies here

action:
    - service: switch.turn_off
      data:
        entity_id: switch.bathroom_tv, switch.charlottes_bedroom_light, switch.charlottes_tv_left, switch.charlottes_tv_right, switch.downstairs_bathroom_light, switch.games_consoles, switch.home_audio_1, switch.home_audio_1a, switch.home_audio_1b, switch.home_audio_1c, switch.home_audio_1d, switch.home_audio_2, switch.home_audio_2a, switch.home_audio_2b, switch.home_audio_2c, switch.home_audio_2d, switch.home_office_tv_left, switch.home_office_tv_right, switch.katies_tv_left, switch.katies_tv_right, switch.kitchen_light, switch.kitchen_tv_left, switch.kitchen_tv_right, switch.living_room_light, switch.living_room_tv_left, switch.living_room_tv_right, switch.master_bedroom_light, switch_master_bedroom_tv_b, switch.master_bedroom_tv_c, switch.master_bedroom_tv_d, switch.media_equipment_cupboard, switch.projector_and_screen, switch.utility_room_light, switch.xboxone, light.flux_living_room_tv

I think your syntax for the “entity_id” is wrong. Shouldn’t it be like this:

action:
  - service: switch.turn_off
      data:
        entity_id: 
          - switch.bathroom_tv
          - switch.charlottes_bedroom_light
          - ...

Just wondering, but couldn’t you use a scene instead of a script?

@123 i tried your change … put this in and get an error

Changed automation:

  action:
    - service: homeassistant.turn_off
      entity_id: switch.bathroom_tv, switch.charlottes_bedroom_light, switch.charlottes_tv_left, switch.charlottes_tv_right, switch.downstairs_bathroom_light, switch.games_consoles, switch.home_audio_1, switch.home_audio_1a, switch.home_audio_1b, switch.home_audio_1c, switch.home_audio_1d, switch.home_audio_2, switch.home_audio_2a, switch.home_audio_2b, switch.home_audio_2c, switch.home_audio_2d, switch.home_office_tv_left, switch.home_office_tv_right, switch.katies_tv_left, switch.katies_tv_right, switch.kitchen_light, switch.kitchen_tv_left, switch.kitchen_tv_right, switch.living_room_light, switch.living_room_tv_left, switch.living_room_tv_right, switch.master_bedroom_light, switch_master_bedroom_tv_b, switch.master_bedroom_tv_c, switch.master_bedroom_tv_d, switch.media_equipment_cupboard, switch.projector_and_screen, switch.utility_room_light, switch.xboxone, light.flux_living_room_tv

error:
Invalid config for [automation]: not a valid value for dictionary value @ data['action'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 1162). Please check the docs at https://home-assistant.io/components/automation/

@Burningstone tried the format you suggested and it also errors

Changed Automation:

  action:
    - service: switch.turn_off
        data:
          entity_id: 
            - switch.bathroom_tv
            - switch.charlottes_bedroom_light
            - switch.charlottes_tv_left 
            - switch.charlottes_tv_right 
            - switch.downstairs_bathroom_light 
            - switch.games_consoles
            - switch.home_audio_1
            - switch.home_audio_1a
            - switch.home_audio_1b
            - switch.home_audio_1c
            - switch.home_audio_1d
            - switch.home_audio_2
            - switch.home_audio_2a
            - switch.home_audio_2b
            - switch.home_audio_2c
            - switch.home_audio_2d
            - switch.home_office_tv_left
            - switch.home_office_tv_right
            - switch.katies_tv_left
            - switch.katies_tv_right
            - switch.kitchen_light
            - switch.kitchen_tv_left
            - switch.kitchen_tv_right
            - switch.living_room_light
            - switch.living_room_tv_left
            - switch.living_room_tv_right
            - switch.master_bedroom_light
            - switch_master_bedroom_tv_b
            - switch.master_bedroom_tv_c
            - switch.master_bedroom_tv_d
            - switch.media_equipment_cupboard
            - switch.projector_and_screen
            - switch.utility_room_light
            - switch.xboxone

Error:

Error loading /config/configuration.yaml: mapping values are not allowed here
  in "/config/automations.yaml", line 19, column 13

I was afraid that might be the case.

FWIW, this:

switch.one, switch.two, switch.three

is functionally equivalent to this:

- switch.one
- switch.two
- switch.three

However, the sheer length of the list (885 characters) makes me wonder, and this is pure speculation, if it exceeds some internal limit for string-length.

I suggest you create a group, containing that lengthy list of entities, and then simply refer to it in the automation.

group:
  my_list:
    entities:
      - switch.bathroom_tv
      - switch.charlottes_bedroom_light
      - switch.charlottes_tv_left
      - switch.charlottes_tv_right
      - switch.downstairs_bathroom_light
      - switch.games_consoles
      - switch.home_audio_1
      - switch.home_audio_1a
      - switch.home_audio_1b
      - switch.home_audio_1c
      - switch.home_audio_1d
      - switch.home_audio_2
      - switch.home_audio_2a
      - switch.home_audio_2b
      - switch.home_audio_2c
      - switch.home_audio_2d
      - switch.home_office_tv_left
      - switch.home_office_tv_right
      - switch.katies_tv_left
      - switch.katies_tv_right
      - switch.kitchen_light
      - switch.kitchen_tv_left
      - switch.kitchen_tv_right
      - switch.living_room_light
      - switch.living_room_tv_left
      - switch.living_room_tv_right
      - switch.master_bedroom_light
      - switch_master_bedroom_tv_b
      - switch.master_bedroom_tv_c
      - switch.master_bedroom_tv_d
      - switch.media_equipment_cupboard
      - switch.projector_and_screen
      - switch.utility_room_light
      - switch.xboxone
      - light.flux_living_room_tv
- service: homeassistant.turn_off
  entity_id: group.my_list

EDIT
One of the entities is misspelled. It is listed as switch_master_bedroom_tv_b. Andrew spotted it (see his post below).