I have a hassio/hassos on RPi3, and a xiaomi aquara with a bunch of temperature/door/movement sensors around the house. These get updated either somewhat periodically (eg. temperature), or randomly (door open).
What i’d like is, to automate a http rest GET/POST on every sensor update. So every time a sensor updates its value (temperature changed, someone opened the door, movement detected,…), i want to trigger a HTTP POST/GET (don’t care which) to a server of mine with sensor data.
How would I do that most easily? Most i’ve been able to find is for the hass to accept HTTP requests.
This can be done pretty simply with a couple of steps.
First thing you need to do is using the RESTful command, create your HTTP get request. Once you have done this and restarted HASS it will then appear in your services list.
What you can then do is use this in an automation. Use your sensors as a trigger and then the RESTful command as the action. It would look something like this in your automations.yaml file
alias: door_open
trigger:
platform: state
entity_id: sensor.door_sensor
action:
service: rest_command.server_request
What this does is pretty straight forward. Every time your sensor updates ie state changes, it fires the action which is your rest_command.
There may be other ways to do this but this is how I have something similar running and it works great.
Building on what @akkaria said, you can pass data to the RESTful command (see RESTful Command for details and an example.) So you can simply list all the entities for which you want to send updates in a single automation, then use the trigger variable to get the details of what changed and what it changed to. E.g.: