MQTT items in sitemap (SOLVED)

  • Platform information:
    • Hardware: NAS
    • OS: Linux
    • Java Runtime Environment: OH runs in a docker environment, so not sure.
    • openHAB version: 2.5.10
  • Issue of the topic: If a switch is being defined in the sitemap and it is based upon a mqtt thing, it shows both: the switch as well as text.

Dear readers,

I have defined a MQTT thing to subscribe (and publish) on MQTT. This is working fine (binding is up since it can read and changes when a change is posted onto MQTT and when changed in OH is is being posted towards MQTT).

However: when I restart OH the switch only shows the switch name and the switches next to it (as it is supposed to). After the switch has been used, it also shows the state next to the switch. This only occurs when it concerns a MQTT item.


My thing definition:

Thing topic EvohomeFastOff {
    Type switch : EvohomeFastOff_zone00 "Evohome Woonkamer Off" [ commandTopic="/EvohomeFastOff/zone00" ]

My item definition:
Switch Evohome_WoonkamerFastOff “Evohome Woonkamer Off” { channel=“mqtt:topic:myUnsecureBroker:EvohomeFastOff:EvohomeFastOff_zone00” }

My sitemap definition:
Switch item=Evohome_WoonkamerFastOff mappings=[ON=“OFF”] icon=“switch-on”

The switch should function as a push switch (which is working fine), the only problem is: the text next to the switch.

I assume it is a very silly thing, but can’t find any solution. If someone could share his idea, that would be fine.

Best regards.

When you restart openHAB or reload a .items file, all your Items are initialized to the special state NULL. Only when the Item gets an update (in this case receives a message after starting up) does the Item change state away from NULL. NULL and another special state UNDEF are represented on the sitemap as -.

You either need to configure the device that is sending the message to use a retained message (retained messages stay on the topic so when OH comes back up and resubscribes to the topic the old message is delivered) or configure persitence with restoreOnStartup in which case OH will load the most recently saved state of the Item from a database and update the Item with that at startup.

Hi rlkoshak,

I know: retain can be defined within MQTT or a ‘refresh on startup’ in OH, but that is not the issue. I wonder how to remove ‘ON’ next to ‘OFF’. The switch is defined to show only the ‘OFF’ button, but it also shows the actual state. If possible, I would like to show only the button (like in a normal definition, only the button is vissible and not the actual state).

Best regards, HWL

Oh, that. I think if you define an empty state formatting string in the label it will be removed. Though if I recall, there were some instances where that didn’t work correctly.

Switch Evohome_WoonkamerFastOff “Evohome Woonkamer Off []”

Bindings are able to provide hints to the way that Items get displayed in sitemaps. That is probably happening here.

Hi Rich,

Thx. That solved it. When I read your suggestion, I could have thought of it myself. :slight_smile:

Superb. Best regards.