Not a HA question. I need to publish the value of a BME280 sensor that uses ESPHome to a third party MQTT broker and I can’t for the life of me work the syntax out!
I know this “on_value” syntax is wrong but could someone suggest what the correct way of doing this is?
That’s ok, ESPHome questions are welcome too. You got the right category.
You have specified boat as a topic prefix in your mqtt setup block. You don’t need to include it in the publish topic. Also you need to include an id and your payload should be:
Thanks @tom_l and I use MQTT Explore already. A great tool! I have another small issue though, when looking at the results of your suggested code in MQTT Explore, you see that because of the mqtt.publish_json you get a key/value pair (e.g. {“Outside Illuminance”:0)} (Please ignore the mixing of temperature, pressure, illuminance etc - that’s just me messing around with different BMP280 sensor values and clearly not relevant to the issue)
For my application, that doesn’t work and I need it to read
temperature = 24
I guessed that I should use mqtt.publish (no JSON) instead but again struggling to find the correct syntax as this doesn’t work and gives the above result ("id(outside_pressure).state).
Thanks, @tom_l and I did try that but I then end up with:
signalk.yaml:45:28: error: could not convert 'outside_temp->esphome::sensor::Sensor::state' from 'float' to 'std::string {aka std::basic_string<char>}'
And couldn’t find a way to cast a float to a string
“Why are you doing this” Great question with a long answer.
A mate of mine owns a boat. The Swiss pocket knife for boat automation is a system called SignalK, which totally a totally amazing tool. Many boaters run ESP8266 sensors (to check their battery banks, bildges etc) and their platform of choice for them is something called SensESP.
Back to my mate… He’s an accountant and there is no way in the world that he can get VisualStudio set up and compile and flash his own ESP sensors to connect to SignalK so I’m looking for an alternative for him to use. Given that SignalK acts as an MQTT broker and ESPHome can publish MQTT events, it seems to make total sense to try to connect them and let ESPHome publish data to SignalK.
This makes sense as ESPHome is about 5000% easier to configure compared to SensESP especially given the recent updates on its deployment features.
That’s what I’m trying to do but, ESPHome needs to deliver the data to SignalK in the correct format and that’s where my questions originate from. It’s very, very close but just not close enough so if you could make some further suggestions I would really appreciate it for all the boaters out there
I managed to sort it out - it was actually quite simple. Need to tidy up the formatting a bit and then I’ll post a complete yaml file here if people want to do the same.