-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Matter 1.3 Water leak detectors (#21456)
* Create Matter_Plugin_2_Sensor_Waterleak.be * Update Matter_Plugin_2_Sensor_Waterleak.be * Create Matter_Plugin_3_Bridge_Sensor_Waterleak.be * Create Matter_Plugin_9_Virt_Sensor_Waterleak.be * Update Matter_UI.be * Update be_matter_module.c * Update Matter_UI.be * Solidify Matter * Solidified new Matter files * Solidified new Matter files
- Loading branch information
Showing
10 changed files
with
1,223 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_2_Sensor_Waterleak.be
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# | ||
# Matter_Plugin_2_Sensor_Waterleak.be - implements the behavior for a Water leak Sensor | ||
# | ||
# Copyright (C) 2024 Stephan Hadinger & Theo Arends | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import matter | ||
|
||
# Matter plug-in for core behavior | ||
|
||
#@ solidify:Matter_Plugin_Sensor_Waterleak,weak | ||
|
||
class Matter_Plugin_Sensor_Waterleak : Matter_Plugin_Device | ||
static var TYPE = "waterleak" # name of the plug-in in json | ||
static var DISPLAY_NAME = "Waterleak" # display name of the plug-in | ||
static var ARG = "switch" # additional argument name (or empty if none) | ||
static var ARG_HINT = "Switch<x> number" | ||
static var ARG_TYPE = / x -> int(x) # function to convert argument to the right type | ||
static var UPDATE_TIME = 750 # update every 750ms | ||
static var UPDATE_COMMANDS = matter.UC_LIST(_class, "Waterleak") | ||
static var CLUSTERS = matter.consolidate_clusters(_class, { | ||
0x0045: [0], # Boolean State p.70 - no writable | ||
}) | ||
# MATTER_WATER_LEAK_DETECTOR_DEVICE_TYPE_ID 0x0043 | ||
static var TYPES = { 0x0043: 1 } # Waterleak Sensor, rev 1 | ||
|
||
var tasmota_switch_index # Switch number in Tasmota (one based) | ||
var shadow_leak | ||
|
||
############################################################# | ||
# Constructor | ||
def init(device, endpoint, config) | ||
super(self).init(device, endpoint, config) | ||
self.shadow_leak = false | ||
end | ||
|
||
############################################################# | ||
# parse_configuration | ||
# | ||
# Parse configuration map | ||
def parse_configuration(config) | ||
self.tasmota_switch_index = int(config.find(self.ARG #-'switch'-#, 1)) | ||
if self.tasmota_switch_index <= 0 self.tasmota_switch_index = 1 end | ||
end | ||
|
||
############################################################# | ||
# Update shadow | ||
# | ||
def update_shadow() | ||
super(self).update_shadow() | ||
if !self.VIRTUAL | ||
var switch_str = "Switch" + str(self.tasmota_switch_index) | ||
|
||
var j = tasmota.cmd("Status 8", true) | ||
if j != nil j = j.find("StatusSNS") end | ||
if j != nil && j.contains(switch_str) | ||
var state = (j.find(switch_str) == "ON") | ||
|
||
if (self.shadow_leak != state) | ||
self.attribute_updated(0x0045, 0x0000) | ||
end | ||
self.shadow_leak = state | ||
end | ||
end | ||
end | ||
|
||
############################################################# | ||
# read an attribute | ||
# | ||
def read_attribute(session, ctx, tlv_solo) | ||
var TLV = matter.TLV | ||
var cluster = ctx.cluster | ||
var attribute = ctx.attribute | ||
|
||
# ==================================================================================================== | ||
if cluster == 0x0045 # ========== Boolean State ========== | ||
if attribute == 0x0000 # ---------- StateValue / bool ---------- | ||
if self.shadow_leak != nil | ||
return tlv_solo.set(TLV.BOOL, self.shadow_leak) | ||
else | ||
return tlv_solo.set(TLV.NULL, nil) | ||
end | ||
end | ||
|
||
end | ||
return super(self).read_attribute(session, ctx, tlv_solo) | ||
end | ||
|
||
############################################################# | ||
# update_virtual | ||
# | ||
# Update internal state for virtual devices | ||
def update_virtual(payload_json) | ||
var val_onoff = payload_json.find("Waterleak") | ||
if val_onoff != nil | ||
val_onoff = bool(val_onoff) | ||
if self.shadow_leak != val_onoff | ||
self.attribute_updated(0x0045, 0x0000) | ||
self.shadow_leak = val_onoff | ||
end | ||
end | ||
super(self).update_virtual(payload_json) | ||
end | ||
|
||
end | ||
matter.Plugin_Sensor_Waterleak = Matter_Plugin_Sensor_Waterleak |
110 changes: 110 additions & 0 deletions
110
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_3_Bridge_Sensor_Waterleak.be
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# | ||
# Matter_Plugin_Bridge_Sensor_Waterleak.be - implements Waterleak Sensor via HTTP to Tasmota | ||
# | ||
# Copyright (C) 2024 Stephan Hadinger & Theo Arends | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import matter | ||
|
||
# Matter plug-in for core behavior | ||
|
||
#@ solidify:Matter_Plugin_Bridge_Sensor_Waterleak,weak | ||
|
||
class Matter_Plugin_Bridge_Sensor_Waterleak : Matter_Plugin_Bridge_HTTP | ||
static var TYPE = "http_waterleak" # name of the plug-in in json | ||
static var DISPLAY_NAME = "Waterleak" # display name of the plug-in | ||
static var ARG = "switch" # additional argument name (or empty if none) | ||
static var ARG_HINT = "Switch<x> number" | ||
static var ARG_TYPE = / x -> int(x) # function to convert argument to the right type | ||
static var UPDATE_TIME = 5000 # update every 5s | ||
static var UPDATE_CMD = "Status 8" # command to send for updates | ||
|
||
static var CLUSTERS = matter.consolidate_clusters(_class, { | ||
0x0045: [0], # Boolean State p.70 - no writable | ||
}) | ||
static var TYPES = { 0x0043: 1 } # Waterleak Sensor, rev 1 | ||
|
||
var tasmota_switch_index # Switch number in Tasmota (one based) | ||
var shadow_Waterleak | ||
|
||
############################################################# | ||
# Constructor | ||
def init(device, endpoint, arguments) | ||
super(self).init(device, endpoint, arguments) | ||
self.tasmota_switch_index = int(arguments.find(self.ARG #-'switch'-#, 1)) | ||
if self.tasmota_switch_index <= 0 self.tasmota_switch_index = 1 end | ||
end | ||
|
||
############################################################# | ||
# Stub for updating shadow values (local copies of what we published to the Matter gateway) | ||
# | ||
# This call is synnchronous and blocking. | ||
def parse_update(data, index) | ||
if index == 8 # Status 8 | ||
var state = false | ||
|
||
state = (data.find("Switch" + str(self.tasmota_switch_index)) == "ON") | ||
|
||
if self.shadow_Waterleak != nil && self.shadow_Waterleak != bool(state) | ||
self.attribute_updated(0x0045, 0x0000) | ||
end | ||
self.shadow_Waterleak = state | ||
end | ||
end | ||
|
||
############################################################# | ||
# read an attribute | ||
# | ||
def read_attribute(session, ctx, tlv_solo) | ||
var TLV = matter.TLV | ||
var cluster = ctx.cluster | ||
var attribute = ctx.attribute | ||
|
||
# ==================================================================================================== | ||
if cluster == 0x0045 # ========== Boolean State ========== | ||
if attribute == 0x0000 # ---------- StateValue / bool ---------- | ||
if self.shadow_Waterleak != nil | ||
return tlv_solo.set(TLV.BOOL, self.shadow_Waterleak) | ||
else | ||
return tlv_solo.set(TLV.NULL, nil) | ||
end | ||
end | ||
|
||
end | ||
return super(self).read_attribute(session, ctx, tlv_solo) | ||
end | ||
|
||
############################################################# | ||
# web_values | ||
# | ||
# Show values of the remote device as HTML | ||
def web_values() | ||
import webserver | ||
self.web_values_prefix() # display '| ' and name if present | ||
webserver.content_send(format("Waterleak%i %s", self.tasmota_switch_index, self.web_value_onoff(self.shadow_Waterleak))) | ||
end | ||
|
||
# Show prefix before web value | ||
def web_values_prefix() | ||
import webserver | ||
var name = self.get_name() | ||
if !name | ||
name = "Switch" + str(self.tasmota_switch_index) | ||
end | ||
webserver.content_send(format(self.PREFIX, name ? webserver.html_escape(name) : "")) | ||
end | ||
end | ||
matter.Plugin_Bridge_Sensor_Waterleak = Matter_Plugin_Bridge_Sensor_Waterleak |
35 changes: 35 additions & 0 deletions
35
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_9_Virt_Sensor_Waterleak.be
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
# | ||
# Matter_Plugin_9_Virt_Sensor_Waterleak.be - implements the behavior for a Virtual Waterleak Sensor | ||
# | ||
# Copyright (C) 2024 Stephan Hadinger & Theo Arends | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import matter | ||
|
||
# Matter plug-in for core behavior | ||
|
||
#@ solidify:Matter_Plugin_Virt_Sensor_Waterleak ,weak | ||
|
||
class Matter_Plugin_Virt_Sensor_Waterleak : Matter_Plugin_Virt_Sensor_Waterleak | ||
static var TYPE = "v_waterleak" # name of the plug-in in json | ||
static var DISPLAY_NAME = "v.Waterleak" # display name of the plug-in | ||
static var ARG = "" # no arg for virtual device | ||
static var ARG_HINT = "_Not used_" # Hint for entering the Argument (inside 'placeholder') | ||
static var VIRTUAL = true # virtual device | ||
|
||
end | ||
matter.Plugin_Virt_Sensor_Waterleak = Matter_Plugin_Virt_Sensor_Waterleak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.