MQTT items

Dear all,
so now, latest part of my adventure… ESP8266 (NodeMCU) with ESPEasy, a reed switch, Mosquitto MQTT broker, OH2…

I can get OH2 to display the sensor:

Kind-of working:

Items:
Number MQTTLED { mqtt="<[mosquitto:/ESP_Easy/reed/contact:state:default]" }

Log:
2017-12-26 11:25:10.947 [vent.ItemStateChangedEvent] - MQTTLED changed from NULL to 0
2017-12-26 11:26:38.025 [vent.ItemStateChangedEvent] - MQTTLED changed from 0 to 1

Kind-of-point is that the sitemap value is not refreshed, I have to hit F5 on the browser to see it.

Not working:
item:
Number Reed “State [%s]” {mqtt="<[mosquitto:ESP_Easy/reed/contact:state:default]"}

sitemap:
Text item=Reed label=“Test [%s]”

Questions
a) why does the first item work but not the second?
b) do I need the leading “/” in front of ESP_Easy.
Online many examples seem to contain it, but the binding tutorial does not.

Thanks as always

Update:

I subscribed via terminal to all messages to have a look out and get:

/ESP_Easy/reed/contact

So I guess for some reason, in my setup the leading forward slash is needed.
(And it makes sense, I check my ESP_Easy config and it had the leading slash).

Next 2 questions:
a) Why BASIC UI does not update in real-time (or with a minor lag)?
b) The reed switch is contacted to my gas-meter.
1 Rotation of the gas-meter disc = X m3 of Gas flow.

I want to define a variable that accumulates number of rotations (i.e. number of state changes from 0 to 1)
Ideally logging it and plotting.

Any advice?

Mine don’t have a leading forward slash.
Also, with the second one, you’ve asked for a string item [%s]” to be displayed rather than a number item

Why are you using a number item type for a contact rather than a contact item type as in:

Contact MQTTLED “State [%s]”  { mqtt="<[mosquitto:ESP_Easy/reed/contact:state:default]" }
Contact Reed “State [%s]” {mqtt="<[mosquitto:ESP_Easy/reed/contact:state:default]"}

Now the UI works well. Thanks:

sitemap:
Text item=ReedSwitch1 icon="switch" label="Test [%s]"

items:
Number ReedSwitch1 "State" <switch> (BS, gSensors) {mqtt="<[mosquitto:/ESP_Easy/reed/contact:state:default]"}

Now for logging and plotting… plot continues (pun intended)

1 Like

Getting there, now I have:

Rules:
var GasCount = 0

rule "test"
when   
		Item ReedSwitch1 changed from 0 to 1
then
		GasCount = GasCount + 1
		GasCounter.postUpdate(GasCount)		
end

items:
Number ReedSwitch1 “State” (BS, gSensors) {mqtt="<[mosquitto:/ESP_Easy/reed/contact:state:default]"}
Number GasCounter “Light sensor 1 [%.1f m3]”

sitemap:
Text item=ReedSwitch1 icon=“switch” label="Test [%s]"
Text item=GasCounter label=“Light sensor 1 [%.0f m3]”