The sensor is working fine, even if I restart HA, sensor status is always at sync with HA front end.
The problem is if the sensor changes state when there is no power on the wemos side,
status is not updated on HA frontend when sensor comes back online again.
Any ideas how to setup the wemos sensors on HA so that they are always at sync?
I believe something like this is crusial if I want to use HA for security purposes.
ideally you should have it run a status check after a power cycle and publish that message, or when HA starts have it ask the device its current status.
That’s the principle I’m looking, just dont know how to implement it on code.
Hassio runs on PI model 3 with mosquitto broker. Wemos D1 mini runs on Tasmota.
Any suggestions?
You could drop Tasmota and go with ESPEasy. It allows you to run rules at boot up. Then you just poll the pin and publish the message. I only have 1 device with tasmota ( a sonoff as a fan switch) but for all my Wemos D1 devices I use ESPEasy because it’s just better. So much more it can do.
In ESP easy I set it up as a normal switch in Devices, and I have enabled in Tools advanced the MQTT Retain Msg. The reed switch is connected in GPIO-14 D5. I have also enabled the rules. (nothing there though yet)
With these settings so far, ESPeasy behaves like tasmota on HA. State out of sync on power loss.
Anything else I can do so HA and Wemos are always at sync?
if you go into advanced you can look check a box for ‘Rules’. Then you get a new menu option. inside that you can just have a routine that runs on bootup.
Also you need to make sure that your topics are the same across devices. something as simple as a capital letter or a / can mess it up. With the retain flag it should be subscribing after power cycle and getting the last status, which makes it sound like a bad topic somewhere. If you can work the command line watch your MQTT messages and see what’s being pub/sub’d to the broker.
So any suggestions of actual code to write on espeasy rules that will work?
Anyone with an actual solution of code either on Tasmota or on ESPeasy fw that has worked for him?
We want a sensor to be able to send its current status after the sensor restarts or after it connects to mqtt.
Pretty fundamental for any kind of on/off sensor.
forsquirel, you nailed it. Thank you very very much !!!
I was testing possible solution for days without any luck but with your guidance I got the result I wanted.
Yes, / and capital letters or not, are enough to mess your result completely.
Took me a lot of reading, trial and error to get here. But you were right.
Using a Wemos D1 Mini and a plain reed switch and HA.
For others, the working code that I end up using in ESP Easy Rules is:
on MQTT#Connected do
if [Reed#Status] = 1
publish %sysname%/Reed/Status,1
else
publish %sysname%/Reed/Status,0
endif
endon
Reed and Status are the Switch Name and Value Name accordingly under Devices in ESP Easy mega-20180504 fw.
%sysname% is the Unit Name under Config in ESP Easy fw. Used a variable so no matter how I name the rest of my door/window sensors in the fw I can always use the same rule.
Using MQTT#Connected covers all bases. No matter if power/WiFi or HA is down when Wemos module connects to MQTT, HA will always show the correct sensor status!
When a device is offline the LWT message gets published. Essentially all you need to do is have a sensor that reads the current message and if it ever hits your LWT (Which you can make whatever you want such as, Disconnected, Offline, Oh My! I’m dead! and so on) then HA will react to the sensor update and there you go.
mta:
when a wemos D1 with ESPEasy boots up it connects to the broker and throws out a LWT message such as ha/motionOne/status/LWT Connected which tells the broker that it has indeed connected to the system. Now should it go offline the last LWT message gets published, but published by the broker since the client told the broker the LWT message upon connect. So no when your device goes offline or unresponsive you’ll see ha/motionOne/status/LWT Connection Lost and there for knowing there’s an issue. hope this makes sense. i’m tired, really tired and need sleep. but good look on your en devours
Keep in mind that I am a hardware guy. I have no background or any knowledge on programming.
I am learning all these the slow and painfull way.
forsquirel you 're awesome. Thank you very much again for the guidance and your patience.
Now, I have a door sensor that states open or closed on HA, and I have a separate power sensor that states if the first sensor is actually online or offline. Both perform and behave excellent.
If I wanted the door sensor to state open or close but when it is offline to state as unavailable on HA,
which way would be best to do that? Availability topic and values on the door sensor (tried that but only works for me if door sensor is offline when HA restart) or some automation that gets triggered by the power sensor and passes the value to the door sensor?
With this availability topic and those payload values if the sensor is available/online shows open/close state accordingly as normal behaviour. If the sensor is not available/offline shows as unavailable in HA and mdi:icon gets greyed.
If anyone has any suggestion for better code I would love to hear it.
I m only learning.
Thanks, but I’m still learning myself and some of it is still a guessing game for me. There’s so many different firmwares and devices that just trying to keep up can get overwhelming.