Skip to content

Commit

Permalink
Don't send units if they don't exist
Browse files Browse the repository at this point in the history
When a unit_of_measurement exists, Home Assistant assumes it's an integer and tries to graph it. Even if no unit_of_measurement are given. By not adding them, Home Assistant takes the value as discrete and visualizes it accordingly.

It's only relevant for few registers. I am using it for "work_state_1".  What the broken graph in Home Assistant looks like at the moment: https://imgur.com/JB67fax. After removing units_of_measurement: https://imgur.com/6rYNAAA and combined with other data: https://imgur.com/1TzAqFd. work_state_1 shows not only "Run" and "Standby", but "Starting" and "Degraded Run" as well which is important for monitoring.
  • Loading branch information
lucahammer authored Apr 19, 2022
1 parent 733f962 commit b232c43
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions SunGather/exports/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def publish(self, inverter):
config_msg['unique_id'] = "inverter_" + self.cleanName(ha_sensor.get('name'))
config_msg['state_topic'] = self.mqtt_config['topic']
config_msg['value_template'] = "{{ value_json." + ha_sensor.get('register') + " }}"
config_msg['unit_of_measurement'] = inverter.getRegisterUnit(ha_sensor.get('register'))
if inverter.getRegisterUnit(ha_sensor.get('register')):
config_msg['unit_of_measurement'] = inverter.getRegisterUnit(ha_sensor.get('register'))
if ha_sensor.get('dev_class'):
config_msg['device_class'] = ha_sensor.get('dev_class')
if ha_sensor.get('state_class'):
Expand All @@ -108,4 +109,4 @@ def publish(self, inverter):
self.ha_discovery_published = True
logging.info("MQTT: Published Home Assistant Discovery messages")

return True
return True

0 comments on commit b232c43

Please sign in to comment.