How can I trigger a HTTP GET/POST on every sensor update?

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
  platform: state
  entity_id: sensor.door_sensor
  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.

Hope this helps.

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

  - alias: Send updates
      platform: state
        - climate.therm1
        - binary_sensor.door1
      service: rest_command.my_command
        name: "{{ or trigger.entity_id }}"
        value: >
          {% if trigger.to_state.domain == 'climate' %}
            {{ trigger.to_state.attributes.current_temperature }}
          {% else %}
            {{ trigger.to_state.state }}
          {% endif %}
1 Like