Page 1 of 1

MQTT

Posted: 26 May 2023, 07:31
by nuiler
MQTT point in comma

How can I convert a value 0.18234 to 0.18234 so that I can calculate with it?

Re: MQTT

Posted: 26 May 2023, 09:00
by TD-er
I think you meant "0,18234" as input?
Where do you get this value from?
Is it via MQTT import or via commands and using C005?

Re: MQTT

Posted: 26 May 2023, 09:15
by nuiler
I get the value via Generic - MQTT import.

What means via commands and using C005.

Can I change the dot to a comma

Re: MQTT

Posted: 26 May 2023, 09:41
by TD-er
C005 is the OpenHab/HomeAssistant controller in ESPEasy.

As shown in its documentation, you can also subscribe to topics crafted in such a way that they represent commands for ESPEasy. See: https://espeasy.readthedocs.io/en/lates ... d-handling

As you can also craft commands to generate an event, and the comma is the separator of parameters (called eventvalues in ESPEasy), you could combine those separate eventvalues into a single value.

Ton does have a lot of work recently on the MQTT import plugin, which he also documents very well: https://espeasy.readthedocs.io/en/lates ... #p037-page

I did have a quick look, but right now I can't think of a way how to replace those decimal commas.
Maybe he has some idea...

Re: MQTT

Posted: 26 May 2023, 10:07
by Ath
Best idea so far is to change it at the source, as we are expecting US/Intl. formatted decimal numbers, not localized decimal numbers.

Re: MQTT

Posted: 26 May 2023, 20:13
by Ath
It turned out to be quite easy, just enable the 'Generate events for accepted topics' option in the MQTT Import task and add a rule for your MQTT topic to 'convert' and assign the value like this:

Code: Select all

on mqtt/topic/cmd do // Handle the MQTT Topic event from MQTT Import
  Let,1,%eventvalue1%.%eventvalue2% // The initial comma separates the values into 2 arguments
  LogEntry,'Value: %v1%' // Optional logging of the value
  TaskvalueSet,Variables,Dummy1,[var#1] // Assign the value to a Dummy task to be used elsewhere, or immediately use it somewhere else like on a display
endon