-
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.
Adding Matter Flow sensor support (#19852)
* Create Matter_Plugin_3_Sensor_Flow.be * Create Matter_Plugin_Bridge_Sensor_Flow.be * Create Matter_Plugin_9_Virt_Sensor_Flow.be * Update Matter_Plugin_3_Sensor_Flow.be 0x0404 Flow Measurement cluster * Rename Matter_Plugin_Bridge_Sensor_Flow.be to Matter_Plugin_4_Bridge_Sensor_Flow.be * Update Matter_UI.be * Update be_matter_module.c * Update be_matter_module.c * Fixes * Update be_matter_module.c * Update Matter_Plugin_9_Virt_Sensor_Flow.be * Update Matter_Plugin_3_Sensor_Flow.be * Update be_matter_module.c * Update solidified_Matter_Plugin_9_Virt_Sensor_Flow.h
- Loading branch information
Showing
9 changed files
with
853 additions
and
5 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
86 changes: 86 additions & 0 deletions
86
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_3_Sensor_Flow.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,86 @@ | ||
# | ||
# Matter_Plugin_Sensor_Flow.be - implements the behavior for a Flow Sensor | ||
# | ||
# Copyright (C) 2023 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_Flow,weak | ||
|
||
class Matter_Plugin_Sensor_Flow : Matter_Plugin_Sensor | ||
static var TYPE = "flow" # name of the plug-in in json | ||
static var DISPLAY_NAME = "Flow" # display name of the plug-in | ||
static var JSON_NAME = "Flow" # Name of the sensor attribute in JSON payloads | ||
static var UPDATE_COMMANDS = matter.UC_LIST(_class, "Flow") | ||
static var CLUSTERS = matter.consolidate_clusters(_class, { | ||
0x0404: [0,1,2,0xFFFC,0xFFFD], # Flow Measurement | ||
}) | ||
static var TYPES = { 0x0306: 2 } # Flow Sensor, rev 2 | ||
|
||
############################################################# | ||
# Pre-process value | ||
# | ||
# This must be overriden. | ||
# This allows to convert the raw sensor value to the target one, typically int | ||
def pre_value(val) | ||
return val != nil ? int(val) : nil | ||
end | ||
|
||
############################################################# | ||
# Called when the value changed compared to shadow value | ||
# | ||
# This must be overriden. | ||
# This is where you call `self.attribute_updated(<cluster>, <attribute>)` | ||
def value_changed() | ||
self.attribute_updated(0x0404, 0x0000) | ||
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 == 0x0404 # ========== Flow Measurement 2.4 p.98 ========== | ||
if attribute == 0x0000 # ---------- MeasuredValue / i16 ---------- | ||
if self.shadow_value != nil | ||
return tlv_solo.set(TLV.I2, int(self.shadow_value)) # MeasuredValue represents the flow in m3/h | ||
else | ||
return tlv_solo.set(TLV.NULL, nil) | ||
end | ||
elif attribute == 0x0001 # ---------- MinMeasuredValue / i16 ---------- | ||
return tlv_solo.set(TLV.I2, 0) # 500 m3/h | ||
elif attribute == 0x0002 # ---------- MaxMeasuredValue / i16 ---------- | ||
return tlv_solo.set(TLV.I2, 65534) # 65534 m3/h | ||
elif attribute == 0xFFFC # ---------- FeatureMap / map32 ---------- | ||
return tlv_solo.set(TLV.U4, 0) # 0 = no Extended Range | ||
elif attribute == 0xFFFD # ---------- ClusterRevision / u2 ---------- | ||
return tlv_solo.set(TLV.U4, 3) # 3 = New data model format and notation | ||
end | ||
|
||
else | ||
return super(self).read_attribute(session, ctx, tlv_solo) | ||
end | ||
end | ||
|
||
end | ||
matter.Plugin_Sensor_Flow = Matter_Plugin_Sensor_Flow |
96 changes: 96 additions & 0 deletions
96
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_4_Bridge_Sensor_Flow.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,96 @@ | ||
# | ||
# Matter_Plugin_Bridge_Sensor_Flow.be - implements base class for a Flow Sensor via HTTP to Tasmota | ||
# | ||
# Copyright (C) 2023 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_Flow,weak | ||
|
||
class Matter_Plugin_Bridge_Sensor_Flow : Matter_Plugin_Bridge_Sensor | ||
static var TYPE = "http_flow" # name of the plug-in in json | ||
static var DISPLAY_NAME = "Flow" # display name of the plug-in | ||
|
||
static var CLUSTERS = matter.consolidate_clusters(_class, { | ||
0x0404: [0,1,2,0xFFFC,0xFFFD], # Flow Measurement | ||
}) | ||
static var TYPES = { 0x0306: 2 } # Flow Sensor, rev 2 | ||
|
||
############################################################# | ||
# Called when the value changed compared to shadow value | ||
# | ||
# This must be overriden. | ||
# This is where you call `self.attribute_updated(<cluster>, <attribute>)` | ||
def value_changed() | ||
self.attribute_updated(0x0404, 0x0000) | ||
end | ||
|
||
############################################################# | ||
# Pre-process value | ||
# | ||
# This must be overriden. | ||
# This allows to convert the raw sensor value to the target one, typically int | ||
def pre_value(val) | ||
return val != nil ? int(val) : nil | ||
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 == 0x0404 # ========== Flow Measurement 2.1.2 p.127 ========== | ||
if attribute == 0x0000 # ---------- MeasuredValue / i16 ---------- | ||
if self.shadow_value != nil | ||
return tlv_solo.set(TLV.I2, int(self.shadow_value)) # MeasuredValue represents the flow in m3/h | ||
else | ||
return tlv_solo.set(TLV.NULL, nil) | ||
end | ||
elif attribute == 0x0001 # ---------- MinMeasuredValue / i16 ---------- | ||
return tlv_solo.set(TLV.I2, 0) # 500 m3/h | ||
elif attribute == 0x0002 # ---------- MaxMeasuredValue / i16 ---------- | ||
return tlv_solo.set(TLV.I2, 65534) # 65534 m3/h | ||
elif attribute == 0xFFFC # ---------- FeatureMap / map32 ---------- | ||
return tlv_solo.set(TLV.U4, 0) # 0 = no Extended Range | ||
elif attribute == 0xFFFD # ---------- ClusterRevision / u2 ---------- | ||
return tlv_solo.set(TLV.U4, 3) # 3 = New data model format and notation | ||
end | ||
|
||
else | ||
return super(self).read_attribute(session, ctx, tlv_solo) | ||
end | ||
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("⛅ %i m3/h", | ||
int(self.shadow_value))) | ||
end | ||
|
||
end | ||
matter.Plugin_Bridge_Sensor_Flow = Matter_Plugin_Bridge_Sensor_Flow |
34 changes: 34 additions & 0 deletions
34
lib/libesp32/berry_matter/src/embedded/Matter_Plugin_9_Virt_Sensor_Flow.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,34 @@ | ||
# | ||
# Matter_Plugin_9_Virt_Sensor_Flow.be - implements the behavior for a Flow Sensor | ||
# | ||
# Copyright (C) 2023 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_Flow,weak | ||
|
||
class Matter_Plugin_Virt_Sensor_Flow : Matter_Plugin_Sensor_Flow | ||
static var TYPE = "v_flow" # name of the plug-in in json | ||
static var DISPLAY_NAME = "v.Flow" # 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_Flow = Matter_Plugin_Virt_Sensor_Flow |
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.