[Solved] MQTT state topic subscription sends wrong updates to Item

Hello Community,

I thought after 4 years of OH usage I am familiar with everything, but today I ran into an issue which drives me crazy…

I run OH 3.4 with Mosquitto MQTT broker, I already use a lot of MQTT states and commands as I have a lot of Tasmotas runnig.

Lately I installed EVCC on another Pi and connected it with my mosquitto, which actually works flawless. For example, I am interested in a special topic called evcc/site/tariffEffectivePrice:

openhabian@openhab:~ $ mosquitto_sub -v -h localhost -p 1883 -t 'evcc/site/tariffEffectivePrice'
evcc/site/tariffEffectivePrice 0.23455
evcc/site/tariffEffectivePrice 0.23421
evcc/site/tariffEffectivePrice 0.2352
evcc/site/tariffEffectivePrice 0.23774
evcc/site/tariffEffectivePrice 0.23983
evcc/site/tariffEffectivePrice 0.2436

I wanted to show this value in my sitemap, so I configured a new channel in my MQTT-Thing:

and mapped it to a number item:

Now what happens is, this item is not updated according to the values I can show with mosquitto-sub. Instead, it is slowly “growing” some digits behind the comma:

2023-05-12 13:48:28.512 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from NULL to 0.080002
2023-05-12 14:45:26.059 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from 0.080002 to 0.080003
2023-05-12 15:01:53.145 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from 0.080003 to 0.080004
2023-05-12 15:20:56.094 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from 0.080004 to 0.080005
2023-05-12 15:29:25.979 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from 0.080005 to 0.080006
2023-05-12 15:40:15.906 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_EffectivePrice' changed from 0.080006 to 0.080007

I repeated the same procedure declaring another item as a string and mapping it to another channel with the same topic, but it behaves exactly the same.

Any ideas why the item is not updated to the values I see when subscribing to it via the command line? It seems to me that OH is adding or integrating the values internally.

Restarting OH also did not help.

Screen shots are a problem on the forum. They can’t be searched, copied/edited/pasted, and on small screens they can’t even be read. Where it’s available always click the “Code” tab and paste the contents using code fences so we get the full config and context.

```
code goes here
```

For an example of what’s missing here that we’d see in the code is what type of Channel this is.

Seeing the full code might also help us answer that. With the given information :person_shrugging: . It might help to see what values are being posted as well. And knowing what they are posted as (number, String, binary, etc.).

Argh, I actually first had the code in the posting, but then I changed for the screenshot.

So here goes the code for the channel:

- id: EVCC_Savings_Effective_Price
    channelTypeUID: mqtt:number
    label: EVCC effektiver Preis
    description: ""
    configuration:
      stateTopic: evcc/site/savingsEffectivePrice

The strange thing is: For testing purposes, I used a new channel with another topic:

- id: EVCC_Effective_Price_String
    channelTypeUID: mqtt:string
    label: EVCC Effektiver Preis String
    description: ""
    configuration:
      stateTopic: evcc/site/homePower

and mapped it to another item. And this item updates nicely as the MQTT state changes:

2023-05-12 16:32:39.677 [INFO ] [openhab.event.ItemUpdatedEvent      ] - Item 'EVCC_Effektiver_Preis_String' has been updated.
2023-05-12 16:32:45.716 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from NULL to 1068
2023-05-12 16:32:55.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1068 to 1075.7
2023-05-12 16:33:05.729 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1075.7 to 1064.2
2023-05-12 16:33:15.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1064.2 to 1029.5
2023-05-12 16:33:25.704 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1029.5 to 1112.7
2023-05-12 16:33:35.709 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1112.7 to 1061.8
2023-05-12 16:33:45.817 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1061.8 to 1165.5
2023-05-12 16:33:55.715 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1165.5 to 1183.4
2023-05-12 16:34:05.710 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1183.4 to 1091.9
2023-05-12 16:34:15.712 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1091.9 to 1121.1
2023-05-12 16:34:25.706 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1121.1 to 1150.7
2023-05-12 16:34:35.764 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1150.7 to 1122.4
2023-05-12 16:34:45.715 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1122.4 to 1140.5
2023-05-12 16:34:55.734 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1140.5 to 1098.3
2023-05-12 16:35:05.723 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1098.3 to 1091.2
2023-05-12 16:35:15.697 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1091.2 to 1094.5
2023-05-12 16:35:25.810 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 1094.5 to 502.52
2023-05-12 16:35:35.707 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 502.52 to 471.87
2023-05-12 16:35:45.714 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 471.87 to 465.56
2023-05-12 16:35:55.708 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 465.56 to 368.01
2023-05-12 16:36:05.731 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 368.01 to 458.84
2023-05-12 16:36:15.696 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 458.84 to 462.53
2023-05-12 16:36:25.877 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 462.53 to 516.94
2023-05-12 16:36:35.699 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 516.94 to 424.2
2023-05-12 16:36:45.706 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'EVCC_Effektiver_Preis_String' changed from 424.2 to 491.15

Argh… it was a typical 18" problem… the problem was 18" away from the screen.

I simply messed with the topics which have similar names. I watched

evcc/site/tariffEffectivePrice 0.2352

with mosquitto_sub but I used

evcc/site/savingsEffectivePrice 0.080007

in the channel config of the MQTT-channel. Sorry, my own fault.

Sometimes all you need is a rubber duck.

2 Likes