Skip to content
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

DECT Window sensors #81

Closed
pohly opened this issue Dec 3, 2022 · 20 comments
Closed

DECT Window sensors #81

pohly opened this issue Dec 3, 2022 · 20 comments
Milestone

Comments

@pohly
Copy link

pohly commented Dec 3, 2022

Should https://github.com/bb-Ricardo/fritzinfluxdb/blob/main/fritzinfluxdb/classes/fritzbox/service_definitions/homeauto.py (from #44?) already work for window and door sensors (for example, https://www.smarthome.de/geraete/smarthome-tuer-fensterkontakt-optisch-weiss)?

I updated to 1.1.0 and I can see that something gets stored in influxdb:

name=Bad, ha_product_name=HAN-FUN, ha_manufacturer=0x0feb, ha_device_present=1

But there's no field for "open/closed".

Here's the result of http://fritz.box/webservices/homeautoswitch.lua?sid=[SesionID]&switchcmd=getdevicelistinfos

<devicelist version="1" fwversion="7.29"><device identifier="11324 0299919" id="413" functionbitmask="1" fwversion="30.17.02.02.011" manufacturer="0x2c3c" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Keller</name></device><device identifier="11324 0299919-1" id="2000" functionbitmask="8208" fwversion="0.0" manufacturer="0x2c3c" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Keller</name><etsiunitinfo><etsideviceid>413</etsideviceid><unittype>513</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp>1665073872</lastalertchgtimestamp></alert></device><device identifier="11934 0184820" id="414" functionbitmask="1" fwversion="31.20" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>WC</name></device><device identifier="11934 0184820-1" id="2001" functionbitmask="8208" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>WC</name><etsiunitinfo><etsideviceid>414</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp>1670064494</lastalertchgtimestamp></alert></device><device identifier="11934 0113004" id="415" functionbitmask="1" fwversion="31.35" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Bad</name></device><device identifier="11934 0113004-1" id="2002" functionbitmask="8208" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Bad</name><etsiunitinfo><etsideviceid>415</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>1</state><lastalertchgtimestamp>1670091174</lastalertchgtimestamp></alert></device><device identifier="11934 0198863" id="406" functionbitmask="1" fwversion="31.35" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Garage</name></device><device identifier="11934 0198863-1" id="2003" functionbitmask="8208" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Garage</name><etsiunitinfo><etsideviceid>406</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp>1670078511</lastalertchgtimestamp></alert></device><device identifier="11324 0207049" id="409" functionbitmask="1" fwversion="30.17.02.02.010" manufacturer="0x2c3c" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Terasse</name></device><device identifier="11324 0207049-1" id="2004" functionbitmask="8208" fwversion="0.0" manufacturer="0x2c3c" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Terasse</name><etsiunitinfo><etsideviceid>409</etsideviceid><unittype>513</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp>1670090658</lastalertchgtimestamp></alert></device></devicelist>

Note the difference between one sensor which is closed:

<name>WC</name><etsiunitinfo><etsideviceid>414</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>0</state><lastalertchgtimestamp>1670064494</lastalertchgtimestamp></alert>

and one which is open:

<name>Bad</name></device><device identifier="11934 0113004-1" id="2002" functionbitmask="8208" fwversion="0.0" manufacturer="0x0feb" productname="HAN-FUN"><present>1</present><txbusy>0</txbusy><name>Bad</name><etsiunitinfo><etsideviceid>415</etsideviceid><unittype>514</unittype><interfaces>256</interfaces></etsiunitinfo><alert><state>1</state><lastalertchgtimestamp>1670091174</lastalertchgtimestamp></alert>

<alert><state> changes. I double-checked that it goes back to 0 when closing.

@bb-Ricardo
Copy link
Owner

Hi,

I don't think this is currently implemented due to examples.

Thanks for the output. I will try to add it asap.

Inlet you know once it has been added.

@bb-Ricardo
Copy link
Owner

Hi,

I had a quick look at it and it seems that this integration takes a little bit longer then I thought.

<devicelist version="1" fwversion="7.29">
	<device identifier="11324 0299919" id="413" functionbitmask="1" fwversion="30.17.02.02.011" manufacturer="0x2c3c" productname="HAN-FUN">
		<present>1</present>
		<txbusy>0</txbusy>
		<name>Keller</name>
	</device>
	<device identifier="11324 0299919-1" id="2000" functionbitmask="8208" fwversion="0.0" manufacturer="0x2c3c" productname="HAN-FUN">
		<present>1</present>
		<txbusy>0</txbusy>
		<name>Keller</name>
		<etsiunitinfo>
			<etsideviceid>413</etsideviceid>
			<unittype>513</unittype>
			<interfaces>256</interfaces>
		</etsiunitinfo>
		<alert>
			<state>0</state>
			<lastalertchgtimestamp>1665073872</lastalertchgtimestamp>
		</alert>
	</device>
</devicelist>

for some reason the device shows up twice in the list. Then we need fwversion from the first device and return it for the second device.

It appears that the second device is a "sub-device" of the first one. Like a chassi with additional modules.

How does this look like in your FritzBox UI. Do you mind sharing?

@bb-Ricardo
Copy link
Owner

Well,

reading the Documentation helps 😅

1.1 HAN-FUN
Die FRITZ!Box unterstützt das HAN FUN App Layer Protokoll der (DECT-)ULE Alliance. Auf avm.de finden sie eine Liste der unterstützten HAN-FUN-Geräte(siehe Unterstützung von DECT-ULE/HAN-FUN)
HAN-FUN benutzt ein Konzept von Units je HAN-FUN-Gerät. So kann es zum Beispiel mehrere Alarm-Units oder OnOff-Units je HAN-FUN-Gerät geben. Eine Unit hat einen Unit-Type(z.B. Beweungsmelder oder dimmbare Farb-Lampe) und eine Liste von unterstützten HAN-FUN-Interfaces(z.B. Alert, OnOff, Color oder Level/Helligkeit). Die Unit hat einen eigenen Identifier, der benutzt werden muss, wenn ein (Schalt-, Helligkeits-)Befehl an die Unit gesendet werden soll.

Then let's add these device types.

@pohly
Copy link
Author

pohly commented Dec 4, 2022

I can run from source, if you want me to try something out.

@bb-Ricardo
Copy link
Owner

Started implementing this but won't be able to finish it today.

The next few days I will definitely get back to your offer 😉

@bb-Ricardo
Copy link
Owner

Hi,

I added support for "HUN-FUN" devices. Can you please check out next-release and see if the data is being created correctly and sent to influx?

Thank you

@pohly
Copy link
Author

pohly commented Dec 6, 2022

I can see that it does something:

DEBUG: 2022-12-06 12:56:05+00:00: ha_devicefunctions=Alarm Sensor, HAN-FUN-Unit ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_devicefunctions=Alarm Sensor, HAN-FUN-Unit ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_devicefunctions=Alarm Sensor, HAN-FUN-Unit ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_devicefunctions=Alarm Sensor, HAN-FUN-Unit ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_devicefunctions=Alarm Sensor, HAN-FUN-Unit ({'box': 'fritz.box', 'name': 'Terasse'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_device_present=1 ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_device_present=1 ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_device_present=1 ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_device_present=1 ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_device_present=1 ({'box': 'fritz.box', 'name': 'Terasse'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_interfaces=[{'@identifier': '11324 0299919-1', '@id': '2000', '@functionbitmask': '8208', '@fwversion': '30.17.02.02.011', '@manufacturer': '0x2c3c', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Keller', 'etsiunitinfo': {'etsideviceid': '413', 'unittype': 'DOOR_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1665073872'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0184820-1', '@id': '2001', '@functionbitmask': '8208', '@fwversion': '31.20', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'WC', 'etsiunitinfo': {'etsideviceid': '414', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670329738'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0113004-1', '@id': '2002', '@functionbitmask': '8208', '@fwversion': '31.35', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Bad', 'etsiunitinfo': {'etsideviceid': '415', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670269797'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0198863-1', '@id': '2003', '@functionbitmask': '8208', '@fwversion': '31.35', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Garage', 'etsiunitinfo': {'etsideviceid': '406', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670309589'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11324 0207049-1', '@id': '2004', '@functionbitmask': '8208', '@fwversion': '30.17.02.02.010', '@manufacturer': '0x2c3c', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Terasse', 'etsiunitinfo': {'etsideviceid': '409', 'unittype': 'DOOR_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670322481'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}] ({'box': 'fritz.box'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_unittype=DOOR_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 12:56:05+00:00: ha_hun_fun_unittype=DOOR_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Terasse'})

I can also see new fields (ha_hun_fun_unittype, ha_hun_fun_interfaces). Of these the latter looks more like a debug dump:

[(`[{'@identifier': '11324 0299919-1', '@id': '2000', '@functionbitmask': '8208', '@fwversion': '30.17.02.02.011', '@manufacturer': '0x2c3c', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Keller', 'etsiunitinfo': {'etsideviceid': '413', 'unittype': 'DOOR_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1665073872'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0184820-1', '@id': '2001', '@functionbitmask': '8208', '@fwversion': '31.20', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'WC', 'etsiunitinfo': {'etsideviceid': '414', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670329738'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0113004-1', '@id': '2002', '@functionbitmask': '8208', '@fwversion': '31.35', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Bad', 'etsiunitinfo': {'etsideviceid': '415', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670269797'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11934 0198863-1', '@id': '2003', '@functionbitmask': '8208', '@fwversion': '31.35', '@manufacturer': '0x0feb', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Garage', 'etsiunitinfo': {'etsideviceid': '406', 'unittype': 'WINDOW_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670309589'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}, {'@identifier': '11324 0207049-1', '@id': '2004', '@functionbitmask': '8208', '@fwversion': '30.17.02.02.010', '@manufacturer': '0x2c3c', '@productname': 'HAN-FUN', 'present': '1', 'txbusy': '0', 'name': 'Terasse', 'etsiunitinfo': {'etsideviceid': '409', 'unittype': 'DOOR_OPEN_CLOSE_DETECTOR', 'interfaces': 'SIMPLE_ON_OFF_SWITCHABLE'}, 'alert': {'state': '0', 'lastalertchgtimestamp': '1670322481'}, '@devicefunctions': ['Alarm Sensor', 'HAN-FUN-Unit']}]

I'm not sure how useful that will be.

However, what I don't see is some simple field for "door/window is open". Should there be one?

@bb-Ricardo
Copy link
Owner

Hi @pohly,

it was late last night and added some bugs as well for good measure.

I just pushed a change. Can you have a look if the data looks better now and all fields you are expecting are shown in DEBUG output?

Thank you

@pohly
Copy link
Author

pohly commented Dec 6, 2022

Looks good now, thanks!

DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_interfaces=SIMPLE_ON_OFF_SWITCHABLE ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_interfaces=SIMPLE_ON_OFF_SWITCHABLE ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_interfaces=SIMPLE_ON_OFF_SWITCHABLE ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_interfaces=SIMPLE_ON_OFF_SWITCHABLE ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_interfaces=SIMPLE_ON_OFF_SWITCHABLE ({'box': 'fritz.box', 'name': 'Terasse'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_unittype=DOOR_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_unittype=WINDOW_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_hun_fun_unittype=DOOR_OPEN_CLOSE_DETECTOR ({'box': 'fritz.box', 'name': 'Terasse'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_alert=0 ({'box': 'fritz.box', 'name': 'Keller'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_alert=0 ({'box': 'fritz.box', 'name': 'WC'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_alert=0 ({'box': 'fritz.box', 'name': 'Bad'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_alert=0 ({'box': 'fritz.box', 'name': 'Garage'})
DEBUG: 2022-12-06 14:46:42+00:00: ha_alert=0 ({'box': 'fritz.box', 'name': 'Terasse'})

@pohly
Copy link
Author

pohly commented Dec 6, 2022

It's interesting that the unit types of the magnetic and optic sensors are different. They perform exactly the same function.

@bb-Ricardo
Copy link
Owner

great to hear, now I need to somehow add these devices to the HA dashboard

@bb-Ricardo
Copy link
Owner

Hi @pohly,

I added an updated version of the home automation dashboard. Can you try it out and see if this works for you?

Thank you

@bb-Ricardo bb-Ricardo added this to the 1.2.0 milestone Dec 22, 2022
@pohly
Copy link
Author

pohly commented Dec 22, 2022

I tried uploading grafana/influx2_dashboards/fritzbox_home_automation_dashboard.json to Grafana v9.6.1.

What confused me initially was that the the UI for the query doesn't show where the specified field gets selected. In the JSON, that is here: "filter(fn: (r) => r._measurement == \"$measurement\" and r._field =~ /^ha_alert$/ and r.box =~ /^${boxtag}$/).

Are you writing that by hand or am I missing something in the Grafana UI?

Then there's the problem that it doesn't find any data. I am pointing it at a "fritz-box" data source backed by influxdb with "InfluxQL" as query language. Is that perhaps the problem?

@pohly
Copy link
Author

pohly commented Dec 22, 2022

Yes, it was. Reconfiguring the source to use Flux fixed it.

I also found that I had to set a default bucket in the Grafana source, otherwise I got a "bucket not set" error in the dashboard. Should the dashboard have a way to select the bucket?

@bb-Ricardo
Copy link
Owner

Not really, all dashboards should use the same bucket. If more then one box is used then they can be separated by the box tag.

It should be described here: https://github.com/bb-Ricardo/fritzinfluxdb/blob/main/README.md#grafana

@bb-Ricardo
Copy link
Owner

If this works for you I would close this issue.

@pohly
Copy link
Author

pohly commented Dec 22, 2022

Not really, all dashboards should use the same bucket.

But not all of my dashboards are for data gathered by fritzinfluxdb. I have one bucket configured for it and another bucket where telegraf stores its data.

Anyway, I guess I can work around this (if it's a workaround, not sure) by defining different sources for the same influxdb, each with a different default bucket.

Feel free to close this issue, I think it all works as intended. Thanks for your support!

@bb-Ricardo
Copy link
Owner

Maybe I should add a variable to all Dashboards and set it to default bucket by default.

What do you think?

@bb-Ricardo bb-Ricardo reopened this Dec 23, 2022
@pohly
Copy link
Author

pohly commented Dec 23, 2022

Such a solution sounds better to me, but I am not a Grafana/InfluxDB expert.

@bb-Ricardo
Copy link
Owner

Unfortunately, this is not so easy as I thought.

Yes, the easiest would be a second data source with the correct bucket defined and to use this for the dashboards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants