mpex
(L)
January 6, 2019, 9:46pm
1
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.
*DEPRECATED. I've now moved to using [ESPHome](https://esphome.io/) for my garage door controller. See [here](https://github.com/johnboiles/homeassistant-config/tree/master/esphome) for my ESPHome configs (specifically look at [`garage_door.yaml`](https://github.com/johnboiles/homeassistant-config/blob/master/esphome/garage_door.yaml).*
# esp-garage-opener
Control and monitor your garage door over MQTT with Home Assistant with an ESP8266, a relay, and a magnetic reed switch.
![Open with Siri](https://raw.githubusercontent.com/johnboiles/esp-garage-opener/assets/images/siri-small.gif)
![Open with a button](https://raw.githubusercontent.com/johnboiles/esp-garage-opener/assets/images/button-small.gif)
Uses:
* [NodeMCU 1.0](https://www.amazon.com/HiLetgo-Version-NodeMCU-Internet-Development/dp/B010O1G1ES) ESP8266 Wifi microcontroller (though I'd probably use a [Wemos D1 Mini](https://www.amazon.com/Makerfocus-NodeMcu-Development-ESP8266-ESP-12F/dp/B01N3P763C) if I started over.
* [5V relay](https://www.amazon.com/Tolako-Arduino-Indicator-Channel-Official/dp/B00VRUAHLE) to trigger the door
* [Magnetic reed switch](https://www.amazon.com/uxcell-Window-Sensor-Magnetic-Recessed/dp/B00HR8CT8E) to detect whether the door is open or closed.
* MQTT protocol for communication
* [HomeAssistant](https://home-assistant.io/) and [Homebridge](https://github.com/nfarina/homebridge) running on a [Raspberry Pi 3](https://www.amazon.com/CanaKit-Raspberry-Micro-Supply-Listed/dp/B01C6FFNY4) to make it available to HomeKit (Siri)
## Electronics
The electronics are very simple. The relay is switched by a digital output from the microcontroller (the relay board linked above has a transistor to supply the necessary current to the relay). The reed switch is connected to ground and one of the digital inputs (because the ESP8266 has internal pullups, no extra resistor is necessary). Just connect to the normally disconnected side of your relay to the same two wires running to your existing garage door button.
This file has been truncated. show original
Note the checkDoorState() function in src/main.c.
mpex
(L)
January 6, 2019, 10:41pm
3
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
mpex
(L)
January 11, 2019, 9:40am
5
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
I think I’ll stick to my current idea then
sjee
January 11, 2019, 9:58am
6
MQTT is embedded in HA, check this link .
1 Like
nickrout
(Nick Rout)
January 12, 2019, 8:49pm
7
Mqtt is really the way to do it. Almost every esp8266 iot project uses it.
1 Like