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.
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.
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.
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:
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
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)
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