Is it possible to to take an analog value from a state, and publish it with MQTT? More specifically, I would like to take the temperature from weather underground (’{{ states.sensor.weather_underground_pws.attributes.temp_f }}’) and put the value into a message published my MQTT, to be used by a separate micro-controller.
From doing a little searching / googling about creating service calls. It’s looks like I need to write a python script to implement this. It appears to do this it needs to reside in the config directory (/custom_components/hello_service.py). However I don’t have a config directory currently.
The .homeassistant directory only contains two directories, “dep”, and “tts”. Do I create the file and somehow tell home assistant where its at through the configuration.yalm file?
In all of the examples I have seen, the payload has been a Boolean value, on or off. Can the payload value be a floating point value? Can it be referenced as an attribute, such as ‘{{ states.sensor.weather_underground_pws.attributes.temp_f }}’?
The payload of an MQTT message is a number of bytes, which can be a string, as in my example above, or a string representing a number.
If you supply a number to the payload parameter (or payload_template as you are sending the state of a sensor), it is converted to an ascii equivalent (and so has to be translated back to a number by the receiver).
I don’t have an example of that in yaml, but here is a snippet of an appdaemon script I have, which sends a number
ok thank you! I will just need to test pulling the data from the ‘{{ states.sensor.weather_underground_pws.attributes.temp_f }}’. I believe the self.call_service will be very handy
Just to make sure you are aware, this is an appdaemon call. It is only available if you are using appdaemon - which I highly recommend, but it is a whole new subject.