I have two sensors for my BMW. The battery soc and the range. I need the values to specific mqtt topics, when their state changes.
sensor.i3_120_verbleibende_batterie_in_prozent needs to be published to openWB/set/vehicle/1/get/soc
sensor.i3_120_verbleibende_reichweite_insgesamt needs to be published to openWB/set/vehicle/1/get/range
Whats the easiest way to achieve that? I already saw there’s an integration MQTT statestream, but thats not what I need as I cannot specify the topic where to publish the new state.
Click the overflow menu in the upper right corner (three vertical dots) and select Edit in YAML.
Delete the existing YAML code displayed in the editing window.
Copy the example I provided above and paste it into the Automation Editor’s editing window then click Save.
Do you already have MQTT installed and configured? Because that’s a prerequisite for any MQTT-related project. This automation will fail to publish anything unless you have the MQTT integration installed as well as an MQTT Broker.
Cool, the automation itself works. My only problem ist that the value isn’t transmitted via MQTT correctly.
I have the following configuration: I have MQTT installed on Home Assistant as an addon.
There is another MQTT on my OpenWB-Wallbox.
I have configured the HA Broker to establish a bridge to the OpenWB-MQTT.
#
# bridge to openWB Wallbox
#
connection openwb2
local_clientid openwb2.mosquitto
address 10.0.0.8:1883
#Sensors Controller
topic openWB/system/ip_address in
topic openWB/system/version in
topic openWB/system/lastlivevaluesJson in
#Sensors per Chargepoint
topic openWB/chargepoint/3/get/# in
topic openWB/chargepoint/3/config in
topic openWB/vehicle/# in
topic openWB/bat/6/get/# in
topic openWB/counter/4/get/# in
topic openWB/pv/5/get/# in
topic openWB/set# out
topic openWB/# in
When a MQTT state on the OpenWB changes, I get the update in Homeassistant immediately, so getting values from the other MQTT works properly.
Only when I send values to the other OpenWB MQTT, the value isn’t transported. I validated this behaviour by testing with MQTT Explorer. When I publish the topic openWB/set/vehicle/1/get/soc on the remote MQTT (10.0.0.8), the value gets updated. If I do the same on the Home Assistant MQTT, there is no effect.
One bonus question: In another scenario I have to entities. Both are numbers. Every time, when one of both entities changes it’s state, they need to be summed up and published to a MQTT topic. Can I do the sum operation also within the automation or do I need to create a helper?
Can you give me an example?
The entities names are: solax_today_s_yield solaxslave_today_s_yield