Skip to content

Commit

Permalink
- Changed unique_id
Browse files Browse the repository at this point in the history
- Added two more sensors
  • Loading branch information
alexdelprete committed Feb 27, 2024
1 parent d32e903 commit 6bf2f89
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 4 deletions.
6 changes: 4 additions & 2 deletions custom_components/sinapsi_alfa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def read_modbus_alfa(self):
self.data["potenza_consumata"] = (
self.data["potenza_prodotta"]
- self.data["potenza_immessa"]
+ self.data["potenza_prelevata"],
+ self.data["potenza_prelevata"]
)
self.data["potenza_auto_consumata"] = (
self.data["potenza_prodotta"] - self.data["potenza_immessa"]
Expand All @@ -243,7 +243,7 @@ def read_modbus_alfa(self):
self.data["energia_consumata"] = (
self.data["energia_prodotta"]
- self.data["energia_immessa"]
+ self.data["energia_prelevata"],
+ self.data["energia_prelevata"]
)
self.data["energia_auto_consumata"] = (
self.data["energia_prodotta"] - self.data["energia_immessa"]
Expand All @@ -267,6 +267,8 @@ def read_modbus_alfa(self):
SensorDeviceClass.POWER,
]:
value = round(float(value / 1000), 2)
else:
value = int(value)
self.data[reg_key] = value
_LOGGER.debug(f"(read_modbus_alfa) Data: {self.data[reg_key]}")
except Exception as modbus_error:
Expand Down
22 changes: 21 additions & 1 deletion custom_components/sinapsi_alfa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
"modbus_type": "uint16",
"modbus_addr": 2,
},
{
"name": "Potenza Prelevata Media 15m",
"key": "potenza_prelevata_media_15m",
"icon": "mdi:transmission-tower-import",
"device_class": SensorDeviceClass.POWER,
"state_class": SensorStateClass.MEASUREMENT,
"unit": UnitOfPower.KILO_WATT,
"modbus_type": "uint16",
"modbus_addr": 9,
},
{
"name": "Potenza Immessa",
"key": "potenza_immessa",
Expand All @@ -63,6 +73,16 @@
"modbus_type": "uint16",
"modbus_addr": 12,
},
{
"name": "Potenza Immessa Media 15m",
"key": "potenza_immessa_media_15m",
"icon": "mdi:transmission-tower-export",
"device_class": SensorDeviceClass.POWER,
"state_class": SensorStateClass.MEASUREMENT,
"unit": UnitOfPower.KILO_WATT,
"modbus_type": "uint16",
"modbus_addr": 19,
},
{
"name": "Potenza Prodotta",
"key": "potenza_prodotta",
Expand Down Expand Up @@ -237,7 +257,7 @@
"name": "Data Evento",
"key": "data_evento",
"icon": "mdi:calendar-outline",
"device_class": SensorDeviceClass.DATE,
"device_class": None,
"state_class": None,
"unit": None,
"modbus_type": "uint32",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sinapsi_alfa/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def should_poll(self) -> bool:
@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self._device_sn}_{self._key}"
return f"{DOMAIN}_{self._device_sn}_{self._key}"

@property
def device_info(self):
Expand Down
Binary file added doc/Alfa Modbus Register Map.xlsx
Binary file not shown.
158 changes: 158 additions & 0 deletions doc/alfa-ha-modbus-configuration (original).yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
modbus:
- name: Alfa
type: tcp
host: <AlfaIP>
port: 502
sensors:
- name: Potenza Attiva Prelevata Istantanea
device_class: power
unit_of_measurement: W
state_class: measurement
data_type: uint16
address: 2
count: 1
- name: Potenza Attiva Immessa Istantanea
device_class: power
unit_of_measurement: W
state_class: measurement
data_type: uint16
address: 12
count: 1
- name: Potenza Attiva Prodotta Istantanea
device_class: power
unit_of_measurement: W
state_class: measurement
data_type: uint16
address: 921
count: 1
- name: Energia Attiva Prelevata Totale
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 5
count: 2
- name: Energia Attiva Immessa Totale
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 15
count: 2
- name: Energia Attiva Prodotta Totale
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 924
count: 2
- name: Pot Att Prel Quart Media
device_class: power
unit_of_measurement: W
state_class: measurement
data_type: uint16
address: 9
count: 1
- name: Pot Att Imm Quart Media
device_class: power
unit_of_measurement: W
state_class: measurement
data_type: uint16
address: 19
count: 1
- name: Tot Energ Att Prel Giorno-1 F1
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 30
count: 2
- name: Tot Energ Att Prel Giorno-1 F2
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 32
count: 2
- name: Tot Energ Att Prel Giorno-1 F3
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 34
count: 2
- name: Tot Energ Att Prel Giorno-1 F4
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 36
count: 2
- name: Tot Energ Att Prel Giorno-1 F5
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 38
count: 2
- name: Tot Energ Att Prel Giorno-1 F6
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 40
count: 2
- name: Tot Energ Att Imm Giorno-1 F1
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 54
count: 2
- name: Tot Energ Att Imm Giorno-1 F2
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 56
count: 2
- name: Tot Energ Att Imm Giorno-1 F3
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 58
count: 2
- name: Tot Energ Att Imm Giorno-1 F4
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 60
count: 2
- name: Tot Energ Att Imm Giorno-1 F5
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 62
count: 2
- name: Tot Energ Att Imm Giorno-1 F6
device_class: energy
unit_of_measurement: Wh
state_class: total_increasing
data_type: uint32
address: 64
count: 2
- name: Fascia oraria corrente
data_type: uint16
address: 203
count: 1
- name: Data evento
data_type: uint32
address: 780
count: 2
- name: Tempo residuo distacco
data_type: uint16
address: 782
count: 1

0 comments on commit 6bf2f89

Please sign in to comment.