I have browsed the forums/internet and haven’t been able to find the code required to do this simple task. I’m not a coder so for me I’m not exactly sure which is the right path to go.
I have done the above, got it working in HA perfectly but I can’t seem to get the distance value to show. If someone could please check the code for me and help me out that would be most appreciated, thanks!
The .ino file in the project doesn’t send the actual distance. At line 152 it just published a 1 or a 0 for open or closed. This based on the ‘’‘isdooropen()’’’ function I think (I’m not that good at Arduino).
You’ll need to modify this sketch to output the distance instead of the boolean open/closed value.
You could have both the boolean and the actual value publish to seperate Matt topics, or you could just publish the distance and use HA to do the rest.
Alternatviely, you could look at using esphomelib. It supports this sensor, OTA updates, and sensor value smoothing (it’s really nice). There’s even a hassio add-on that integrates nicely with HA if you’re using hassio.
I think you’re right. The ultrasonic library is supplying a distance value, you just want to publish it to mqtt instead of (or along with) the state boolean being calculated. Investing in learning esphomelib is only useful if you see yourself deploying a bunch of other boards for other uses.
The MQTT broker isn’t though. I did manage to get ESPEasy firmware onto the controller but I can’t communicate with my windows based HA due to the MQTT having no username and password(I think). So going to try with a Pi Setup later and see,
I have only used an nodeMCU once before today but today a new one arrived along with a HC-SR04 and within about an hour from watching various videos I now have distance sensors into HA via ESPHome