Can execute automations but don't run automatically

Hi,

I’m new to the HA world and have got a SONOFF sensor to play with, I created an automation (see automation below) and I can execute it fine, but it doesn’t seem to work automatically.

I am in the home zone

Automation:

*alias: Office door open notification*
*description: Office door open notification*
*trigger:*
*  - platform: state*
*    entity_id: binary_sensor.office_sensor_contact*
*    attribute: contact*
*    from: Closed*
*    to: Open*
*condition:*
*  - condition: device*
*    device_id: 320618f1ecd804abcd747a27e*
*    domain: device_tracker*
*    entity_id: device_tracker.wills_pixel_5*
*    type: is_home*
*action:*
*  - device_id: 320618f1ecd804abcd747a27e*
*    domain: mobile_app*
*    type: notify*
*    message: Office door open*
*    title: Home*
*mode: single*

Hi there…Please share the state and state attribute of binary_sensor.office_sensor_contact* from the developer console.

1 Like
  - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'off'
    to: 'on'
3 Likes

Taras already provided the needed change for the trigger to work.
First, if you execute an automation manually it will skip triggers and conditions and go straight to the action part.
Second, to get the correct values for to: and from: for your trigger, go to Developer Tools -> States and check the state of your entity there. Open/closed is only for the frontend, while the true state is on/off.

1 Like

There’s a service call for automation you can selectively ignore conditions etc as well… Good for checking this stuff.

This makes sense now… really appreciate the help!

Hi Burningstone,

I have changed my automation from Closed/Open to Off/On (see below) and I’m still not getting notifications. (do when I execute)

alias: Office door open notification
description: Office door open notification
trigger:
  - platform: state
    entity_id: binary_sensor.office_sensor_contact
    attribute: contact
    from: 'Off'
    to: 'On'
condition:
  - condition: device
    device_id: 320618f1ecd804abcd747a27
    domain: device_tracker
    entity_id: device_tracker.wills_pixel_5
    type: is_not_home
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    after: '08:00'
    before: '17:15'
action:
  - device_id: 320618f1ecd804abcd747a27
    domain: mobile_app
    type: notify
    message: Office door open
    title: Home
mode: single

Lowercase off/on, as Taras posted above. It’s case-sensitive.
As I said you can get the correct state under Developer Tools -> States.

Not all sensors are ‘on’ when door open (some invert) so as Burning and Taras stated you should always check the actual states.

When you are familiar with the devices you can make assumptions, but everyone knows that will sometimes bite them in the ass

1 Like

Ahhh! my bad proper rookie here! :rofl:

Look at your first post. It now has a link beneath it that leads to the post you marked with the Solution tag.

Imagine you are a user with the same problem you had. You click the link and are led directly to the Solution post. Except the post you chose doesn’t provide the actual solution to the problem (use a binary_sensor’s correct state values for from and to). Now the user must read more of the thread to find the real solution.

2 Likes

After all the above info people have provided I still seem to be having problems see below methods I have tried:

 - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'off'
    to: 'on'
 - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'on'
    to: 'off'
 - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'true'
    to: 'false'
 - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'false'
    to: 'true'

I have been into the developer section and selected the sensor and used, on and off to switch states (shows up on the home page correctly when I go between them(true/false doesn’t seem to change anything))

In zigbee2mqtt when i select the device i see below info under state:

{
    "battery": 73,
    "battery_low": false,
    "contact": true,
    "linkquality": 147,
    "tamper": false,
    "voltage": 2900
}

In zigbee2mqtt when i select the device i see below info under exposes:

contact
Indicates if the contact is closed (= true) or open (= false)
true
battery_low
Indicates if the battery of this device is almost empty
false
tamper
Indicates whether the device is tampered
false
battery
Remaining battery in %
73 %
linkquality
Link quality (signal strength)
147 lqi

All the examples you listed contain the same indentation error.

The options should be indented equally:

 - platform: state
   entity_id: binary_sensor.office_sensor_contact
   from: 'off'
   to: 'on'

Sorry, after looking at the YAML mine is how you showed (not sure why it showed like that in last post)

alias: Office Door Open Notification TEST
description: TEST
trigger:
  - platform: state
    attribute: contact
    from: 'off'
    to: 'on'
    entity_id: binary_sensor.office_sensor_contact
condition:
  - condition: device
    device_id: 320618f1ecd804abcd747a27
    domain: device_tracker
    entity_id: device_tracker.wills_pixel_5
    type: is_not_home
action:
  - device_id: 320618f1ecd804abcd747a27
    domain: mobile_app
    type: notify
    message: Office door open
    title: 'Home:'
mode: single

this still doesn’t seem to be working.

Spacing is still wrong

If this is automations.yaml then the alias key is okay (if elsewhere the wrong)
description: indent 2 more
trigger: indent 4 more
- platform: indent 6 more (I’d do 8 more but I’m weird)
the stuff under that should be inline withh the p of platform
condition: should be as trigger
(ditto the sub keys as trigger)
action: (ditto as condition)

Why have you included this line? Remove it.

    attribute: contact

This is strange as I don’t actually write the automations using YAML, I use the UI view.

missed that one :sob:

It’s what is screwing up the trigger. Instead of monitoring the binary_sensor’s state it’s monitoring a non-existent attribute called contact.

The indentation is fine (and is how the Automation Editor presents an automation’s YAML code).

1 Like

I deleted the automation and started again, I used the UI and the below is untouched YAML.

alias: Notification Office door open
description: TEST
trigger:
  - platform: state
    entity_id: binary_sensor.office_sensor_contact
    from: 'off'
    to: 'on'
condition:
  - condition: device
    device_id: 320618f1ecd804abcd747a27e0f95d1d
    domain: device_tracker
    entity_id: device_tracker.wills_pixel_5
    type: is_not_home
action:
  - device_id: 320618f1ecd804abcd747a27e0f95d1d
    domain: mobile_app
    type: notify
    message: Office door open
    title: Home
mode: single

still no luck!