Skip to content

Commit

Permalink
Merge pull request #12 from bouwew/sensor_updates
Browse files Browse the repository at this point in the history
Implement state_class and device_class for more sensors
  • Loading branch information
bouwew authored Oct 23, 2021
2 parents 2386dfe + 8f761af commit ca75565
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions custom_components/sems2mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt

from homeassistant.components.sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL,
STATE_CLASS_TOTAL_INCREASING,
)
from homeassistant.const import (
CONF_PASSWORD, CONF_USERNAME,
CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_STOP)
Expand Down Expand Up @@ -217,6 +228,8 @@ def create_device(model):
'value_template':'{{ value_json.pgrid_w }}',
'icon':'mdi:solar-power',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_POWER,
'unique_id':'sems_solar_power_sensor',
'device': create_device(data['type'])
}
Expand All @@ -226,6 +239,8 @@ def create_device(model):
'value_template':'{{ value_json.temperature }}',
'icon':'mdi:thermometer',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_TEMPERATURE,
'unique_id':'sems_inverter_temperature_sensor',
'device': create_device(data['type'])
}
Expand All @@ -235,6 +250,8 @@ def create_device(model):
'value_template':'{{ value_json.eday_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_TOTAL,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_today_sensor',
'device': create_device(data['type'])
}
Expand All @@ -244,8 +261,8 @@ def create_device(model):
'value_template':'{{ value_json.etotal_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': "total_increasing",
'device_class': 'energy',
'state_class': STATE_CLASS_TOTAL_INCREASING,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_total_sensor',
'device': create_device(data['type'])
}
Expand All @@ -255,6 +272,8 @@ def create_device(model):
'value_template':'{{ value_json.emonth_kwh }}',
'icon':'mdi:flash',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_TOTAL,
'device_class': DEVICE_CLASS_ENERGY,
'unique_id':'sems_produced_this_month_sensor',
'device': create_device(data['type'])
}
Expand All @@ -264,6 +283,8 @@ def create_device(model):
'value_template':'{{ value_json.grid_voltage }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_grid_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -273,6 +294,8 @@ def create_device(model):
'value_template':'{{ value_json.grid_current }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_grid_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -282,6 +305,8 @@ def create_device(model):
'value_template':'{{ value_json.grid_frequency }}',
'icon':'mdi:current-ac',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': None,
'unique_id':'sems_grid_frequency_sensor',
'device': create_device(data['type'])
}
Expand All @@ -291,6 +316,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_voltage_str_1 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_str_1_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -300,6 +327,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_current_str_1 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_str_1_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -309,6 +338,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_voltage_str_2 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_VOLTAGE,
'unique_id':'sems_str_2_voltage_sensor',
'device': create_device(data['type'])
}
Expand All @@ -318,6 +349,8 @@ def create_device(model):
'value_template':'{{ value_json.dc_current_str_2 }}',
'icon':'mdi:current-dc',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_CURRENT,
'unique_id':'sems_str_2_current_sensor',
'device': create_device(data['type'])
}
Expand All @@ -327,6 +360,8 @@ def create_device(model):
'value_template':'{{ value_json.battery_soc }}',
'icon':'mdi:battery-charging',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': DEVICE_CLASS_BATTERY,
'unique_id':'sems_battery_soc_sensor',
'device': create_device(data['type'])
}
Expand All @@ -336,6 +371,8 @@ def create_device(model):
'value_template':'{{ value_json.battery_soh }}',
'icon':'mdi:medical-bag',
'state_topic':'sems/sensors',
'state_class': STATE_CLASS_MEASUREMENT,
'device_class': None,
'unique_id':'sems_battery_soh_sensor',
'device': create_device(data['type'])
}
Expand Down

0 comments on commit ca75565

Please sign in to comment.