Homie MQTT device

Hi there,
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?

1 Like

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.

Hey @broconne
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/$state init
homie/46843/$homie 3.0.1
homie/46843/$implementation ZenseHome
homie/46843/$name Lampeudtag i Soveværelse
homie/46843/$nodes power,dimmable,wattUsage
homie/46843/power/$name Power
homie/46843/power/$type switch
homie/46843/power/$properties powerProperties
homie/46843/power/powerProperties OFF
homie/46843/power/powerProperties/$name Switch
homie/46843/power/powerProperties/$settable true
homie/46843/power/powerProperties/$format ON,OFF
homie/46843/power/powerProperties/$retained true
homie/46843/dimmable/$name dimmable
homie/46843/dimmable/$type dimmer
homie/46843/dimmable/$properties dimmableProperties
homie/46843/dimmable/dimmableProperties 0
homie/46843/dimmable/dimmableProperties/$name Dimming
homie/46843/dimmable/dimmableProperties/$settable true
homie/46843/dimmable/dimmableProperties/$format 0:100
homie/46843/dimmable/dimmableProperties/$retained true
homie/46843/dimmable/dimmableProperties/$datatype integer
homie/46843/wattUsage/$name Watt usage
homie/46843/wattUsage/$type number
homie/46843/wattUsage/$properties wattUsageProperties
homie/46843/wattUsage/wattUsageProperties 0.0
homie/46843/wattUsage/wattUsageProperties/$name Current watt usage
homie/46843/wattUsage/wattUsageProperties/$settable false
homie/46843/wattUsage/wattUsageProperties/$format 0:2000
homie/46843/wattUsage/wattUsageProperties/$retained true
homie/46843/wattUsage/wattUsageProperties/$unit w
homie/46843/wattUsage/wattUsageProperties/$datatype float
homie/46843/$state ready

Hang on. I forgot to add datatype to the power properties. Once that was done (enum) then it started to work! YES! :slight_smile:

1 Like

Nice! Im working on something similiar using ESP8266 and Homie.
I was writing this post when you saw the error yourself.

homie/46843/power/powerProperties/$retained true

Is this neccesary? All messages should be sent retained with a QOS=1

Hoping for a more complete documentation myself :slight_smile:

Hi Tommy

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?

Br Jonas

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?

https://homieiot.github.io/specification/spec-core-develop/

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/$homie 4.0
homie/Test/$name Gromatic_Sensor_Test
homie/Test/$nodes DHT22,MCU,ADC
homie/Test/MCU/$name MCU
homie/Test/MCU/$type MCU Stats
homie/Test/MCU/$properties uptime
homie/Test/MCU/uptime/$name uptime
homie/Test/MCU/uptime/$settable false
homie/Test/MCU/uptime/$unit s
homie/Test/MCU/uptime/$datatype float
homie/Test/MCU/uptime/$format 0:50000000
homie/Test/$state ready
homie/Test/ADC/$name ADC
homie/Test/ADC/$type ADS1115 4ch ADC
homie/Test/ADC/$properties ADC0,ADC1,ADC2,ADC3
homie/Test/ADC/ADC0/$name ADC0
homie/Test/ADC/ADC0/$settable false
homie/Test/ADC/ADC0/$unit mV
homie/Test/ADC/ADC0/$datatype float
homie/Test/ADC/ADC0/$format 0:50000000
homie/Test/ADC/ADC1/$name ADC1
homie/Test/ADC/ADC1/$settable false
homie/Test/ADC/ADC1/$unit mV
homie/Test/ADC/ADC1/$datatype float
homie/Test/ADC/ADC1/$format 0:50000000
homie/Test/ADC/ADC2/$name ADC2
homie/Test/ADC/ADC2/$settable false
homie/Test/ADC/ADC2/$unit mV
homie/Test/ADC/ADC2/$datatype float
homie/Test/ADC/ADC2/$format 0:50000000
homie/Test/ADC/ADC3/$name ADC3
homie/Test/ADC/ADC3/$settable false
homie/Test/ADC/ADC3/$unit mV
homie/Test/ADC/ADC3/$datatype float
homie/Test/ADC/ADC3/$format 0:50000000
homie/Test/DHT22/$name DHT22
homie/Test/DHT22/$type Air temperature/humidity sensor
homie/Test/DHT22/$properties temperature,humidity
homie/Test/DHT22/temperature/$name temperature
homie/Test/DHT22/temperature/$settable false
homie/Test/DHT22/temperature/$unit ┬░C
homie/Test/DHT22/temperature/$datatype float
homie/Test/DHT22/temperature/$format -20:100
homie/Test/DHT22/humidity/$name humidity
homie/Test/DHT22/humidity/$settable false
homie/Test/DHT22/humidity/$unit %
homie/Test/DHT22/humidity/$datatype float
homie/Test/DHT22/humidity/$format 0:100

Here is my output atm :blush:

Ahr, I hoped you were referring to an OpenHAB specific specification :slight_smile:

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.

1 Like

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 ?
Gudmund

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.