I am sending an MQTT message from a different python machine to my Raspberry Pi 4 running home assistant.
However, I only receive strings, and I am unable to convert this string to a value. Therefore the question: How can I convert this MQTT message string to a value.
The python publish command I am using is the following:
Ah, absolutely right, I copied the wrong line of code in my question above (but my appended python code was correct). Sorry about that. I updated the question to make it correct.
I of course push out the iterator as a string on the python side and while I receive that string correctly I fail to convert it to an integer on the home assistant side.
If you want to perform operations on a sensor state that represents a number, you need to convert it at that point in time. For example, if you wanted to multiply your sensor by ten:
I am trying to convert that string which I receive over mqtt to a number format such that I can plot them in a useful way instead of colored bars. Therefore the Machine current Tag nr variable shall be a number variable. And I am trying to do this âin one goâ such that the variable Machine current Tag nr directly comes out as a number variable.
Does that make sense? Sorry if I have been unclear.
So just for clarification, does HA try to parse that value automatically when the graph is being generated, or is the value parsed as a number directly when HA receives the value?
I have to apologize for the confusion, it definitly was an XY problem!
Entity states are always strings. If you give a sensor a unit_of_measurement, you are indicating that you expect the state to always be a string that âlooks likeâ a number, and the front end will be able to draw graphs based on those ânumbersâ.
If your MQTT source ever publishes a non-numeric state, an error will be generated.