I am testing a portable button from "shelly". As such it is a nice thing 4.5 cm x 4.5 cm and 1.7 cm high. I would like to use it for arming my system.
It publishes a string. It contains 1, 2, 3 times an "S" when pushed the amount of S's. It contains an "L" when pushed long. At the end contains "end_count:" with a number. This number is not always the same.
How can I grab this string and extract the amount of times the button has been pushed or has been pushed longer?
Your advice please.
So basically the point is you get a JSON message and you need to take out specific pieces out of it to store the information in different sensors (e.g. "SS" into a sensor and "1" into another sensor potentially). Is it the case? Thanks
When I receive "S" I have to store "1"
When I receive "SS" I have to store "2"
When I receive "SSS" I have to store "3"
When I receive "L" I have to store "4"
When this would be possible I can use the button for arming, un-arming and killing the siren.
@eporocrail ok, I see two things needed to achieve it:
- a way for service/mqtt to parse a JSON and extract things from the fields so to store just the corresponding value and not the entire json payload (should be an easy enhancement https://github.com/egeoffrey/egeoffrey-service-mqtt/issues/1)
- a post-processor which would count/transform the value in the way you need. This is already available and I would leverage an existing capability rather than implementing something ad-hoc. I can help you with this once #1 will be ready. Theoretically this could work also by parsing the raw json string you already have but it is suboptimal.
I'll let you know once the enhancement will be ready.
@eporocrail this should solve the first item listed above: https://forum.egeoffrey.com/topic/61/updates-for-egeoffrey-service-mqtt-and-egeoffrey-service-zigbee2mqtt
It is working. Only the single values "S", "SS", "SSS" and "L" are entering the sensor.
By creating a constant with value "S", a variable with the "JSON sensor" and a rule which compares both I can set a separate sensor "ON".
That is enough for my needs.
Thanks a lot!!!!!