Push sensor data to HA

Hi,

I’ve built a custom sensor that operates on ultra low power, meaning that the sensor wakes up in a certain interval to tell HA its current status.
Because of this, polling is not possible.

My current approach to connect this to home assistant, is to set up a template sensor and push new data using a post request like this one

curl -X POST -H "Content-Type: application/json" -d '{"state": "25",   "attributes": {"unit_of_measurement": "°C"}}' x.x.x.x/api/states/sensor.low_power_temperature

Is this the right way to do? Are there other approaches to implement a “push data” sensor? My current solution seems a bit hacky, but I could not find good documentation/information so far.

Edit: The microcontroller I use does not support MQTT

I’m very new to HA, but it seems that mqtt is designed for this.

For example in this garage project he pushes the door’s state to HA via mqtt. This is driven from a sensor mounted on the door.

Note the checkDoorState() function in src/main.c.

Thanks for the reply. The microcontroller that I use is unable to support MQTT, so sadly this is not an option.

Ah,’I should have known there was a good reason to resort to curl. If you don’t mind me asking what hardware/controller are you using? Just curious as I’m looking at low cost options for several automation areas.

Thanks

Okay, I learned that MQTT is actually available for the ESP8266.
However, I want to keep things simple and do not want to set up a MQTT Broker for 2 sensors.

More software needs more maintenance :slight_smile:

I think I’ll stick to my current idea then

MQTT is embedded in HA, check this link.

1 Like

Mqtt is really the way to do it. Almost every esp8266 iot project uses it.

1 Like