My first post. I am new to OpenHAB - and new to Homie. So please bear with me…
I have OpenHabian 2.4 running in RPI3. I have created a java program that posts some usually pretty dumb switches to the embedded mqtt broker. Some can dim, some cannot. The autodiscovery feature works - no problem, but when I go into Things it PaperUI it says:
Status: OFFLINE - COMMUNICATION_ERROR java.lang.Exception: Did not receive mandatory topic value: homie/45208/$homie
But it’s there. My format is like this (please correct me, if you see any obvious errors):
homie/45208/$state > init
homie/45208/$homie > 3.0.0
homie/45208/$implementation > ZenseHome
homie/45208/$localip > 192.168.xx.xx:10001
homie/45208/$name > Spots primær
homie/45208/$id > 45208
homie/45208/$type > Lampeudtag m. PIR dæmpbar
homie/45208/$room > Køkken
homie/45208/$properties > power,dimmable,wattUsage
homie/45208/properties/power > OFF
homie/45208/properties/power/$settable > true
homie/45208/properties/power/$format > ON,OFF
homie/45208/properties/power/$retained > true
homie/45208/properties/dimmable > true
homie/45208/properties/dimmable/$settable > true
homie/45208/properties/dimmable/$format > 0:100
homie/45208/properties/dimmable/$retained > true
homie/45208/properties/dimmable/$format > integer
homie/45208/properties/wattUsage > 0.0
homie/45208/properties/wattUsage/$settable > false
homie/45208/properties/wattUsage/$format > 0:2000
homie/45208/properties/wattUsage/$retained > true
homie/45208/properties/wattUsage/$unit > w
homie/45208/properties/wattUsage/$format > float
homie/45208/$state > ready
Do you have any ideas as to what I can do different?
You are sending $homie, but I wonder if the issue is that your are defining dimmable as an integer but sending “true” as your value and that is causing it to stop processing other values. It is just a guess at a cause because I don’t have the code in front of me.
If you are able to use Kotlin instead of Java, I wrote a library with good test coverage that would prevent errors like that.
Thanks for your reply - it’s really appreciated. I might have misunderstood some of the Homie convention, because I though that it was:
homie/45208/properties/dimmable/set > 50
That was to be used, if I wanted to dim the lights to 50.
homie/45208/properties/dimmable > true
was just used to verify that the device IS true. But as stated, I might not get Homie precisely.
I only know Java - so I would have a hard time in changing to Kotlin…
So, I’ve been working a bit more with this and I found the homie validator here: https://homieiot.github.io/tools/
That helped me quite a lot. My device now looks like below paste. Now I can dim the device (only with manual input of numbers though - but it works), and I can see the watt usage. But I can not use the switch. In OpenHAB it doesnt even read the name, so I believe there is an error in one of the inputs. Not sure which one yet.
Does anyone have a link to documentation for MQTT Homie for OpenHAB? Specifically which types are available and examples of data?
homie/46843/$name Lampeudtag i Soveværelse
homie/46843/wattUsage/$name Watt usage
homie/46843/wattUsage/wattUsageProperties/$name Current watt usage
Hang on. I forgot to add datatype to the power properties. Once that was done (enum) then it started to work! YES!
Nice! Im working on something similiar using ESP8266 and Homie.
I was writing this post when you saw the error yourself.
Is this neccesary? All messages should be sent retained with a QOS=1
Hoping for a more complete documentation myself
I am not sure. I have tried setting it to false for power and dimmable, but then they stopped working. I believe they are true as default, so might not be needed.
I still have the issue that OpenHAB doesnt set my power node as a switch, but as a String instead… Can you see what I did wrong there?
I think you need to define it as a Boolean (true/false)… I cant find any references to a “switch” type in the specification atleast.
Also, are you sure you are sending the MQTT payloads with retained flag?
Yes, I am sending it with retained flag… Just trying to change the datatype and removing format for power node. What specification are you looking at?
The reason i asked was that it looks like you are sending all data and paramters each time… Just a matter of formatting i guess.
homie/Test/MCU/$type MCU Stats
homie/Test/ADC/$type ADS1115 4ch ADC
homie/Test/DHT22/$type Air temperature/humidity sensor
Here is my output atm
Ahr, I hoped you were referring to an OpenHAB specific specification
And BONUS - you are right - I set it too boolean and now I have the correct switch. Now it just return true/false instead of ON/OFF. But I can handle that in my device code - so that’s not a big problem for me. THANKS!!!
Yes, I actually am sending all data each time. I can also see that OpenHAB doesn’t update them once I configure them. Should I send the MQTT payloads without a retained flag for that to function, you think?
I am a bit n00b in all this - so have been trying a whole lot to get it to work!
I think of it this way; Send all the parameters and setupinfo as retained payload upon connection to the broker -> send node values and states ie. every other second.
Hello Tommy !
I have integrated an mqtt thing with some 10+ channels.
Have I understood the protocol correctly if I summarize it like this
- Send one time - at boot of Openhap for example - the topics that defines the thing (Init, Home version, nodes, etc, ready)
- On desired intervals, send only topics to update the nodes with the values, such as temperature readings…
Per the 3.0 convention, https://homieiot.github.io/specification/
Device must send its attributes at initial connection and at re connection.
It must send its statistics at an interval as it defines.
Properties updated as they change.
Thank you for this reply.
I must confess that I have problems to differentiate between property and attributes.
Could you by any chance have a working very small example that I can base my own design on showing the bare minimal that is needed ?
I have not quite finished my code, but im happy to share what I have. Will clean it up a little and make it public on github shortly.