hopefully you can help me with receiving one simple mqtt-message: I get a mqtt-message with a time information in format like “2018-01-01 12:14:00” and setupped a thing as followed:
Type datetime : lastTimeSync “MAX_034c92 lastTimeSync” [
stateTopic=“tele/FHEM/HeatingThermostat/MAX_034c92/lastTimeSync”, transformationPattern=“REGEX:(s/\s/T/g)” ]
Since the mqtt-binding only accept a datime in format like “2018-01-01T12:14:00”, I have to insert the “T” in between instead of the white-space.
How can I do this?
Can I use REGEX, JSONPATH or similar for this substitution while reading the mqtt-message, or do I really have to do an post-transformation with a rule or something for this stupid exchange of ONE character?
As I mentioned before, I have also tried
without a chance…
thank you for your suggestion!
The problem is not the presentation, but be able to get this datetime in a calculate-able datetime-format.
The idea is to send an alert/ doing a diagnosis if the last received mqtt-message is “old”. So my hope is to use the transformationPattern for this transformation task.
(A transformationPattern just for cutting out some values - as the transformationPattern seems to be mainly used - is - in my opinion - a oversized naming…).
Hopefully anybody else have another idea?
I am sure, that this kind of solution will also help in other transformation usecases.
Thank You for this hint!
In my optinion this Design Pattern could be a possible workaround for my mentioned transformationPattern-problem.
But: sorry, in this way I am a little bit “old-fashioned”: I do not want to create a new DateTime-item. I just want to transform a datetime mqtt-message nearly “untouched” into a datetime.
I mean: I want to import the datetime exactly with the time-information in the message, not the timestamp of the receiving of any message…
There’s no timezone information in that, you may have to decide if you want to treat it as UTC or as local zone.
You’ve already identified what you need to do; convert your non-standard date-time into ISO format to be parsed into a DateTime type Item. Not an MQTT issue.
But I think you’ll also need to append your chosen timezone info.
One way is to use the openHAB REGEX Transformation Service. This is not exactly regular REGEX, so the online help doesn’t always help.
I don’t understand REGEX, and would do this with a JS transform myself like -
I will restart my raspberry and hope that there is done magic over night (my startup on RPi3 takes 4 hours…) and will answer. Maybe I have also to switch on the demaging log-files again.
Beside working or not: the documentation of the mqtt-binding explains, that REGEX should work (no information about js…). And the documentation of REGEX describes how to substitute an white-space with a “T”.
So: do you mean, that there is a bug in the mqtt-binding regarding transformationPattern or is the bug simply anywhere between display and chair??
Thank You for your detailed description! It helped me a lot and I am sure, that this will be a good fundament for further transformations.
Your solution with a further item calculated by a rule works fine! I will implement it now in three independent systems.
But I am not willing to close this topic until anyone have an smart idea, how to do the transformation right when receiving the mqtt-message:
as I mentioned before, the mqtt-binding seems to support a transformationPattern for incoming messages. This is the way I am looking for. Without any further rule, without any further item (which will be initialised with NULL…).
Just to say it once again: Thank You very much for your solution!!
Yes, this is exactly the payload. There is no timezone delivered. And this is ok for me, since the delivery-system (FHEM) runs on the same CPU with same ntp-access…
On the other hand: the timezone is also not neccessary by the mqtt-binding for receiving datetimes.
SO: does anybody know, how to read the mqtt-payload “2018-01-01 12:14:00” as a datetime?
How to transform this string to “2018-01-01T12:14:00” so that the mqtt-binding will excapt this as datetime?
Is it possible to integrate the upper mentioned .js-file from rossko57 and combine it with transformationPattern?
Thank You very much! This is exactly the solution I was looking for! It works fine!
Your detailed description also helped me with another transformation-topic. So: all upper mentioned solutions/ workarounds helps a lot to learn how to transform values practically.