-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Matter Flow sensor support #19852
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e0348e5
Create Matter_Plugin_3_Sensor_Flow.be
lboue 77406a0
Create Matter_Plugin_Bridge_Sensor_Flow.be
lboue 2793871
Create Matter_Plugin_9_Virt_Sensor_Flow.be
lboue 189840a
Update Matter_Plugin_3_Sensor_Flow.be
lboue 98aaa82
Rename Matter_Plugin_Bridge_Sensor_Flow.be to Matter_Plugin_4_Bridge_…
lboue 69fe0a2
Update Matter_UI.be
lboue c4ae4e2
Update be_matter_module.c
lboue bad8bda
Update be_matter_module.c
lboue 7479c0c
Fixes
lboue e9913fd
Update be_matter_module.c
lboue bbae8bb
Update Matter_Plugin_9_Virt_Sensor_Flow.be
lboue a18421e
Update Matter_Plugin_3_Sensor_Flow.be
lboue cd08202
Update be_matter_module.c
lboue ec195bf
Update solidified_Matter_Plugin_9_Virt_Sensor_Flow.h
lboue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugin_Sensor_Flow
seems to be declared twice