bb-Ricardo/fritzinfluxdb

DECT Window sensors

pohly opened this issue · 20 comments

pohly commented

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.

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.

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?

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 commented

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

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

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

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 commented

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?

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 commented

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 commented

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

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

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

pohly commented

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 commented

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?

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

If this works for you I would close this issue.

pohly commented

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!

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

What do you think?

pohly commented

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

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.