hi,
I have a shelly button1 that i want to use in openhab, my mqtt bridge etc al work fine,
I’m already controlling other stuff with it.
now this is the first time I’m using a ‘button’ a.k.a. a wireless switch that i later want to add to scenes etc…
the topic is shellies/shellybutton1-A4CF12F455A3/input_event/0
but the reply is: '{“event”:“S”,“event_cnt”:9}
S meaning short pres en event_cnt the number of times in total the button has been pressed (not important)
when i try to make it a switch i get 2020-07-07 18:06:04.981 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '{"event":"S","event_cnt":9}' not supported by type 'OnOffValue'
when I make it a string, I get zero erros or nothing in the log
Channels:
this is how it’s in my items file at the moment Type string : msg "Praktijkdeur" [stateTopic="shellies/shellybutton1-A4CF12F455A3/input_event/0"]
You could use a JSONPATH transformation to extract the event, “S”
But then what would you do with it? It is possible to make “S” set a Switch Item ON. That’s less use than it appears, there’s nothing to ever turn it off.
It’s probably worth at this stage looking what else you can get out of it - are there other vents than “S”?
You might want to have the topic just trigger openHAB events, and not set an Item at all.
As @rossko57 mentioned, you can add a JSONPath transformation to extract the S, like so:
Type string : msg "Praktijkdeur" [
stateTopic="shellies/shellybutton1-A4CF12F455A3/input_event/0",
transformationPattern="JSONPATH:$.event"
]
You then attach that to an Item (we can’t give you a full example because we can’t see your entire things file). In your rules, you can then watch that Item, and if it changes receives a command you can perform some actions.
If you also want to catch how many times your button was pressed, simply add another channel to your thing, and extract event_cnt, again using the JSONPath transform.
Note that by default, incoming stateTopic payloads are converted to Item state changes.
You could set a rule up to listen for Item state updates, which still occur for updates-to-same-state.
(We can’t use change, because we wouldn’t see two “S” events)
But in this case where the button press is a “do something” instruction from a user, it fits more comfortably into the openHAB model as a command, same as if you poke a UI button.
The MQTT binding includes a feature to enable this behaviour, the postCommand option.
Seems you’d probably want to do that @jeroenvdd https://www.openhab.org/addons/bindings/mqtt.generic/#channel-configuration
I want to make the thing a switch but atm i get this error:
==> /var/log/openhab2/openhab.log <==
2020-07-08 12:38:27.767 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'S' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.S
Channels:
Type switch : power "Praktijkdeur" [
stateTopic="shellies/shellybutton1/input_event/0",
transformationPattern="JSONPATH:$.event",
on="JSONPATH($.event)]"
]
If you want a rule to listen for a command, then you’ll have to make the MQTT message into a command as advised earlier.
You can link your MQTT string type channel to an openHAB String type Item and listen for command ‘S’. Or just any command at all.
This would also allow for any other tricks your button deviee can do, maybe it sends "D’ for doubleclick, no idea.
No idea what that’s about. Going to guess this is a battery powered device that powers down (drops off WiFi) after use. “Connection reset by peer”
You’re using the embedded Moquette broker. This is known to have minor issues, maybe getting excited about devices dropping offline is one. i have no idea if there is any configuring that might sooth it for this case.
You could live with the logging if it seems to have no ill effects - check especially for delays in use.
Or change to another broker like Mosquitto, as Moquette appears to be end of life with no further fixes coming.