From a97ad48cf32fe7cc266ff6c7481eb1a54cc89a27 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sat, 22 Jul 2023 13:12:46 +0000 Subject: [PATCH] Add frequency sensors for Pro 3EM (#239) --- python_scripts/shellies_discovery_gen2.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python_scripts/shellies_discovery_gen2.py b/python_scripts/shellies_discovery_gen2.py index dd12556..6709277 100644 --- a/python_scripts/shellies_discovery_gen2.py +++ b/python_scripts/shellies_discovery_gen2.py @@ -46,6 +46,7 @@ DEVICE_CLASS_CONNECTIVITY = "connectivity" DEVICE_CLASS_CURRENT = "current" DEVICE_CLASS_ENERGY = "energy" +DEVICE_CLASS_FREQUENCY = "frequency" DEVICE_CLASS_HUMIDITY = "humidity" DEVICE_CLASS_POWER = "power" DEVICE_CLASS_POWER_FACTOR = "power_factor" @@ -165,6 +166,7 @@ SENSOR_ETH_IP = "eth_ip" SENSOR_EXTERNAL_POWER = "external_power" SENSOR_FIRMWARE = "firmware" +SENSOR_FREQUENCY = "frequency" SENSOR_HUMIDITY = "humidity" SENSOR_INPUT = "input" SENSOR_LAST_RESTART = "last_restart" @@ -241,6 +243,7 @@ TPL_EMETER_ACTIVE_POWER = "{{{{value_json.{phase}_act_power}}}}" TPL_EMETER_APPARENT_POWER = "{{{{value_json.{phase}_aprt_power}}}}" TPL_EMETER_CURRENT = "{{{{value_json.{phase}_current}}}}" +TPL_EMETER_FREQUENCY = "{{{{value_json.{phase}_freq}}}}" TPL_EMETER_N_CURRENT = "{{value_json.n_current}}" TPL_EMETER_PHASE_TOTAL_ACTIVE_ENERGY = "{{{{value_json.{phase}_total_act_energy}}}}" TPL_EMETER_PHASE_TOTAL_ACTIVE_RETURNED_ENERGY = ( @@ -252,7 +255,7 @@ TPL_EMETER_TOTAL_ACTIVE_RETURNED_ENERGY = "{{value_json.total_act_ret}}" TPL_EMETER_TOTAL_APPARENT_POWER = "{{value_json.total_aprt_power}}" TPL_EMETER_TOTAL_CURRENT = "{{value_json.total_current}}" -TPL_EMETER_VOLTEAGE = "{{{{value_json.{phase}_voltage}}}}" +TPL_EMETER_VOLTAGE = "{{{{value_json.{phase}_voltage}}}}" TPL_ENERGY = "{{value_json.aenergy.total}}" TPL_ETH_IP = "{{value_json.eth.ip}}" TPL_EXTERNAL_POWER = "{%if value_json.external.present%}ON{%else%}OFF{%endif%}" @@ -302,6 +305,7 @@ UNIT_AMPERE = "A" UNIT_CELSIUS = "°C" UNIT_DBM = "dBm" +UNIT_HERTZ = "Hz" UNIT_PERCENT = "%" UNIT_VOLT = "V" UNIT_VA = "VA" @@ -654,6 +658,16 @@ KEY_UNIT: UNIT_VOLT, KEY_VALUE_TEMPLATE: TPL_VOLTAGE, } +DESCRIPTION_SENSOR_EMETER_FREQUENCY = { + KEY_DEVICE_CLASS: DEVICE_CLASS_FREQUENCY, + KEY_ENABLED_BY_DEFAULT: False, + KEY_NAME: "Phase {phase} frequency", + KEY_STATE_CLASS: STATE_CLASS_MEASUREMENT, + KEY_STATE_TOPIC: TOPIC_EMETER, + KEY_SUGGESTED_DISPLAY_PRECISION: 0, + KEY_UNIT: UNIT_HERTZ, + KEY_VALUE_TEMPLATE: TPL_EMETER_FREQUENCY, +} DESCRIPTION_SENSOR_EMETER_VOLTAGE = { KEY_DEVICE_CLASS: DEVICE_CLASS_VOLTAGE, KEY_ENABLED_BY_DEFAULT: True, @@ -662,7 +676,7 @@ KEY_STATE_TOPIC: TOPIC_EMETER, KEY_SUGGESTED_DISPLAY_PRECISION: 1, KEY_UNIT: UNIT_VOLT, - KEY_VALUE_TEMPLATE: TPL_EMETER_VOLTEAGE, + KEY_VALUE_TEMPLATE: TPL_EMETER_VOLTAGE, } DESCRIPTION_SENSOR_VOLTAGE_COVER = { KEY_DEVICE_CLASS: DEVICE_CLASS_VOLTAGE, @@ -1418,6 +1432,7 @@ SENSOR_TOTAL_ACTIVE_ENERGY: DESCRIPTION_SENSOR_EMETER_PHASE_TOTAL_ACTIVE_ENERGY, SENSOR_TOTAT_ACTIVE_RETURNED_ENERGY: DESCRIPTION_SENSOR_EMETER_PHASE_TOTAL_ACTIVE_RETURNED_ENERGY, SENSOR_VOLTAGE: DESCRIPTION_SENSOR_EMETER_VOLTAGE, + SENSOR_FREQUENCY: DESCRIPTION_SENSOR_EMETER_FREQUENCY, }, ATTR_UPDATES: { UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,