is there a way to use a response of a restful call in an automation condition?
Use case: I have a “Nuki Lock” and want to create an automation, which locks the lock if it is unlocked. The “Nuki Lock” has a door sensor which tells, if the door is open or not. I have integrated this using the rest API as a sensor, but it happens, that the value of the sensor is not up-to-date, when the time-based automation triggers for locking the lock.
I don’t want to increase the scan interval for this sensor too much since this might use too much power of the device.
My plan: I want to create a time-based automation (e.g. each 10 minutes) with condition “Lock is unlocked” and “Door sensor says: closed” (based on an immediate Restful call.
Hope, I’ve explained my problem properly and looking forward for some ideas
How about if door has been closed for 10 minutes but is unlocked, then lock it. Much simpler and no repeated unnecessary time pattern triggers. The 10 minutes should give your sensor time to update too.
trigger:
- platform: state
entity_id: binary_sensor.your_door_sensor
to: 'off' # assuming off == closed
for:
minutes: 10
condition:
- condition: state
entity_id: binary_sensor.lock
state: 'off' # assuming off = unlocked
action:
service: ...<lock your door here>
The other option is to create a template lock that combines your lock sensor and lock into one. When the lock or unlock service is called you can update the rest sensor in the actions.
Here’s an example of updating a sensor in a template switch actions I use: