Skip to content

Commit

Permalink
Update hass_mqtt.py (jblance#299)
Browse files Browse the repository at this point in the history
Sadly Home Assistant only recognises binary sensor states, if they are "ON" or "OFF" (case sensitive). 🤦🏻‍♂️
So there's also the need of changing the values for export.
And also sadly the if condition differs "0" from QPIWS and 0 from QPIGS.
For the QPIWS warnings I cannot see an universal conditon. Maybe you can somehow use the command to include it also in the if. For me I added the tag from mpp-solar.conf section:
if unit == "bool" or value == "enabled" or value == "disabled" or tag == "myQPIWStag":
  • Loading branch information
michas79de authored Jan 11, 2023
1 parent 09dae34 commit 6b1b049
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mppsolar/outputs/hass_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ def build_msgs(self, *args, **kwargs):
# <discovery_prefix>/<component>/[<node_id>/]<object_id>/config
# topic "homeassistant/binary_sensor/garden/config"
# msg '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state", "unit_of_measurement": "°C"}'
if unit == "bool":
if unit == "bool" or value == "enabled" or value == "disabled":
topic = f"homeassistant/binary_sensor/mpp_{tag}_{key}/config"
topic = topic.replace(" ", "_")
name = f"{tag} {_key}"
payload = f'{{"name": "{name}", "state_topic": "homeassistant/binary_sensor/mpp_{tag}_{key}/state", "unique_id": "mpp_{tag}_{key}", "force_update": "true" }}'
msg = {"topic": topic, "payload": payload}
msgs.append(msg)
topic = f"homeassistant/binary_sensor/mpp_{tag}_{key}/state"
if value == 0 or value == "0" or value == "disabled":
# for QPIWS one can add [or tag == "myQPIWStag"], if there's a QPIWS section in mpp-solar.conf
value = "OFF"
elif value == 1 or value == "1" or value == "enabled":
value = "ON"
msg = {"topic": topic, "payload": value}
msgs.append(msg)
else:
Expand Down

0 comments on commit 6b1b049

Please sign in to comment.