Skip to content

Commit

Permalink
Danfoss eTRV0100: Add "External Open Window Detected" support
Browse files Browse the repository at this point in the history
Add support for writing to attribute 0x4003 in order to set
the window status from an external sensors.

The ThermoOnOff type has been used as it was easier than creating
a new type.

Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>
  • Loading branch information
thertp committed Nov 20, 2023
1 parent 7cb9edb commit 027cb2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Modules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
tuya_lidl_set_mode, tuya_trv_brt100_set_mode,
tuya_trv_mode, tuya_trv_onoff,
tuya_trv_switch_onoff)
from Modules.danfoss import danfoss_on_off
from Modules.tuyaTS0601 import ts0601_actuator, ts0601_extract_data_point_infos
from Modules.zigateConsts import (THERMOSTAT_LEVEL_2_MODE,
THERMOSTAT_LEVEL_3_MODE, ZIGATE_EP)
Expand Down Expand Up @@ -504,7 +505,10 @@ def mgtCommand(self, Devices, Unit, Command, Level, Color):

elif DeviceType == "ThermoOnOff":
self.log.logging("Command", "Debug", "ThermoOnOff - requested Off", NWKID)
tuya_trv_onoff(self, NWKID, 0x00)
if "Model" in self.ListOfDevices[NWKID] and self.ListOfDevices[NWKID]["Model"] in ("eTRV0100"):
danfoss_on_off(self, NWKID, 0x00)
else:
tuya_trv_onoff(self, NWKID, 0x00)
UpdateDevice_v2(self, Devices, Unit, 0, "Off", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)

elif DeviceType == "ShutterCalibration":
Expand Down Expand Up @@ -689,7 +693,10 @@ def mgtCommand(self, Devices, Unit, Command, Level, Color):
thermostat_Mode(self, NWKID, "Heat")

elif DeviceType == "ThermoOnOff":
tuya_trv_onoff(self, NWKID, 0x01)
if "Model" in self.ListOfDevices[NWKID] and self.ListOfDevices[NWKID]["Model"] in ("eTRV0100"):
danfoss_on_off(self, NWKID, 0x01)
else:
tuya_trv_onoff(self, NWKID, 0x01)
UpdateDevice_v2(self, Devices, Unit, 1, "On", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)

elif DeviceType == "ShutterCalibration":
Expand Down
36 changes: 36 additions & 0 deletions Modules/danfoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,39 @@ def danfoss_viewdirection(self, NwkId, viewdirection):

write_attribute(self, NwkId, ZIGATE_EP, EPout, cluster_id, manuf_id, manuf_spec, Hattribute, data_type, Hdata, ackIsDisabled=False)
read_attribute(self, NwkId, ZIGATE_EP, EPout, cluster_id, "00", manuf_spec, manuf_id, 1, Hattribute, ackIsDisabled=False)


def danfoss_on_off(self, NwkId, on):
# 0 = window closed 1 = window opened
if on == 0:
window_opened = 1
elif on == 1:
window_opened = 0
else:
return

manuf_id = "1246"
manuf_spec = "01"
cluster_id = "%04x" % 0x0201

EPout = "01"
for tmpEp in self.ListOfDevices[NwkId]["Ep"]:
if "0201" in self.ListOfDevices[NwkId]["Ep"][tmpEp]:
EPout = tmpEp

Hattribute = "%04x" % 0x4003
data_type = "10" # boolean
self.log.logging("Danfoss", "Debug", "danfoss_on_off: %s" % window_opened, nwkid=NwkId)

Hdata = "%02x" % window_opened

self.log.logging(
"Danfoss",
"Debug",
"danfoss_on_onff for %s with value %s / cluster: %s, attribute: %s type: %s" % (NwkId, Hdata, cluster_id, Hattribute, data_type),
nwkid=NwkId,
)

write_attribute(self, NwkId, ZIGATE_EP, EPout, cluster_id, manuf_id, manuf_spec, Hattribute, data_type, Hdata, ackIsDisabled=False)
read_attribute(self, NwkId, ZIGATE_EP, EPout, cluster_id, "00", manuf_spec, manuf_id, 1, Hattribute, ackIsDisabled=False)

0 comments on commit 027cb2b

Please sign in to comment.