Hello, I’m using openhab with a MQTT, and I would like to have one switch change is state when I click in the openHab GUI and when it receives a MQTT message. When I do this, Inbound and Outbound in the same switch, I create a infinite loop, because when I click the button, openhab as a subscriber picks the MQTT message and resends it, and then picks it up again, and the loop goes on and on.
I tried to use rules to controle this, but the “received command”, but I have the same problem. How can I solve this, send and receive MQTT in the same switch?
You also want to change the state of the switch (state is different concept from command), when the far end device publishes to that topic. For example:
<[broker:/your/topic:state:MAP(binary.map)]
If you want to have the state of the switch only change when the remote switch itself changes, and not just the act of the user changing the switch in the UI, then add autoupdate="false".
Hi i have a temperature value that im recieving via this item.
Number ThermostatLoungeCurrentTemp “Temperature [%.1f °C]” {mios=“unit:house,device:48/service/TemperatureSensor1/CurrentTemperature”}
How to i send that value to my MQTT server i have created my topic and can send to it using MQTTLens but everything i try within my items file just fails.
number ThermostatLoungeCurrentTemp { mqtt=">[192.168.31.220:/loungetemp:state"} is one of the many attempts with just no luck.
Thanks Watou i do read the wiki and give them a go before asking as a last resort, a lot of the wikis just dont make sense to me they have a couple of examples etc. do you have any core openhab pages i should read to understand items. sitemaps, maps (thats my next problem im having) and their use and options?
I had a lot of trouble with the emoncms MQTT server but seem to be able to send via HTTP ok from a browser but an having trouble sending this from open hab is my variable cored here?
Have a look at this part of the HTTP binding wiki page that shows the proper format to replace into the URL. You would want to use %2$.1f to substitute the current numeric command or state into the URL.
The given URL can be enhanced using the well known Syntax of the java.util.Formatter. The !HttpOutBinding currently adds to parameters to the String.format() automatically
the current date (as java.util.Date)
the current Command or State
To reference these values the indexed format syntax is used. A well prepared URL look like this:
Each format string starts with ‘%’ followed by an optional index e.g. ‘2$’ whereas ‘2’ is the index of the parameter arg given to the format(format, args…) method. Besides the index you have to specify the format to be applied to the argument. E.g. ‘s’ to format a String in the given example or ‘d’ to format an Integer, or ‘.1f’ to format a Float with one decimal fraction.
I was also tearing my hair out with the following two errors in the openhab.log
given new state is NULL, couldn’t post update for ‘Sprinkler_Z1’
Cannot get service reference for transformation service of type MAP
Then I realised I had to install the Transformation add-on “Map Transformation” , then bingo all worked perfectly!
I have a sprinkler system that is at the other end of a mysensors network. I wanted the mysensors node to report back the status of the sprinkler valve rather than let openhab assume it was activated.
I let show me by MQTT my temperature and humidity of the living room.
Switches via MQTT work also.
But I have problems, when my Sunset Rule switches my switch item to ON, then unfortunately nothing happens via MQTT. But if I switch the switch in the sitemap by hand to ON or OFF, then MQTT is the right one.
rule "SunsetNeu"
when
Time cron "0 * * * * ?"
then
val dtSunset = new DateTime(SunsetStart_Time.state.toString)
val iTimerSunsetStunde = TimerSunsetStunde.state as DecimalType
val iTimerSunsetMinute = TimerSunsetMinute.state as DecimalType
val iMinuteCurrent = now.getMinuteOfDay
val iMinuteSunset = dtSunset.getMinuteOfDay
val iMinuteTimer = iTimerSunsetStunde.intValue * 60 + iTimerSunsetMinute.intValue
if ((iMinuteCurrent >= iMinuteSunset) && (iMinuteCurrent < iMinuteTimer))
{
logInfo("SunsetNeu", "Lichter eingeschaltet")
postUpdate(SunsetStart, ON)
}
else
{
logInfo("SunsetNeu", "Lichter ausgeschaltet")
postUpdate(SunsetStart, OFF)
}
end