VALLHORN Motion Sensor also shows up as Light Sensor "devicetype"
When activating my new (and first) VALLHORN in my python code using this library, I noticed in the callback function handling the Dirigera events, that the VALLHORN also gives an event as deviceType "lightSensor".
The event data looks like
{'id': '2e69259a-615b-4252-b3f8-53ecaeccb94a_3', 'type': 'unknown', 'deviceType': 'lightSensor', 'createdAt': '2024-12-02T20:31:01.000Z', 'isReachable': True, 'lastSeen': '2024-12-02T21:40:52.000Z', 'attributes': {'illuminance': 47}, 'remoteLinks': []}
The get_all_devices call gives another id for the VALLHORN Motion Sensor. It is almost the same except the _1 and _3 on the end.
MotionSensor(id='2e69259a-615b-4252-b3f8-53ecaeccb94a_1', relation_id='2e69259a-615b-4252-b3f8-53ecaeccb94a', type='sensor', device_type='motionSensor', created_at=datetime.datetime(2024, 12, 2, 20, 31, 1, tzinfo=TzInfo(UTC)), is_reachable=True, last_seen=datetime.datetime(2024, 12, 2, 21, 23, 54, tzinfo=TzInfo(UTC)), attributes=MotionSensorAttributes(custom_name='Motion Sensor 1', model='VALLHORN Wireless Motion Sensor', manufacturer='IKEA of Sweden', firmware_version='1.0.64', hardware_version='1', serial_number='70C59CFFFED9562B', product_code='E2134', ota_status=None, ota_state=None, ota_progress=None, ota_policy=None, ota_schedule_start=None, ota_schedule_end=None, battery_percentage=67, is_on=False, light_level=None, is_detected=True), capabilities=Capabilities(can_send=[], can_receive=['customName']), room=Room(id='75efe5a0-0111-4e51-bc4a-ebe4ea94d0b9', name='Werkkamer', color='ikea_yellow_no_28', icon='rooms_office_chair'), device_set=[], remote_links=[], is_hidden=False, dirigera_client=<dirigera.hub.hub.Hub object at 0x1069c9d60>),
I have lights, outlets, environment sensors, remote controllers, water sensors, but the VALLHORN motion sensor is the only device which has a "relation_id" filled in. This appears to be the id without the _1 behind it.
The VALLHORN Motion Sensor is id 2e69259a-615b-4252-b3f8-53ecaeccb94a_1 The light sensing part is id 2e69259a-615b-4252-b3f8-53ecaeccb94a_3
I also get events for the Motion Sensor with id 2e69259a-615b-4252-b3f8-53ecaeccb94a_1 so that is working as it should:
{'id': '2e69259a-615b-4252-b3f8-53ecaeccb94a_1', 'type': 'sensor', 'deviceType': 'motionSensor', 'createdAt': '2024-12-02T20:31:01.000Z', 'isReachable': True, 'lastSeen': '2024-12-02T21:53:30.000Z', 'attributes': {'isDetected': True, 'sensorConfig': {'scheduleOn': False, 'onDuration': 180, 'schedule': {'onCondition': {'time': '22:00'}, 'offCondition': {'time': '06:00'}}}, 'circadianPresets': []}, 'remoteLinks': []}
Am I doing something wrong that the light sensor part of the VALLHORN is not part of the Motion Sensor device?
BTW: I cannot find anything about the light level / illuminance in the IKEA Home Smart app. So it might a future surprise from IKEA.
I was thinking what the best way of implementing this is?
- Creating a new device type "LightSensor" (because there might be other simple LightSensor devices in the future as well) or
- Creating some hack and get that illuminance of the lightSensor side of the VALLHORN in the motionSensor part? or
- Something else?
Motion sensors use PIR (passive infrared) sensors in combination with LUX sensors.
It has multiple benefits.
-
Energy efficiency: Lux sensor measures if the room is sufficiently lit before PIR starts
-
Adaptive lightning, detecting day from night
-
Eftended component life, PIR needs some time before it can be reused again
All IKEA motion sensors have them (Old Tradfri, new Vallhorn).
I've tried making home controlling script based on the luminance of different rooms, but the LUX sensor wasn't firing as much often as I'd want to (I can't remember but I believe it was every 15 minutes). But I was testing it on old Tradfri sensors.
But how do we implement this in dirigera library?
We now have very nice and clean Python classes describing the different types of hardware IKEA is producing.
But what do we do with the lux sensor in the motion sensor? Make the light level part of the motion sensor class? Or do we create a separate class (LightSensor for example) for it (with the downside of having one physical piece of hardware being two classes).
If we make the lux sensor part of the motion sensor ... what do we do whenever IKEA introduces a light bulb with a motion sensor (sounds not too strange). Is that hardware than a Light class in which we implemented motion sensing? Or is it then a Motion Sensor class in which we implement the lighting functions?
Just wondering what the best possible way of solving this is.
My gut feeling says creating a separate class is the way forward however, I realise that it also introduces some awkward cases.
Hey @nestorix1343, I'm not sure I understand correctly. Do you currently get 2 motion sensors in the get_all_devices call for your single Vallhorn?
No, I get 1 motion sensor from get_all_devices, id: '2e69259a-615b-4252-b3f8-53ecaeccb94a_1'.
However, in the event handler I get an event for an "unknown" device with id: '2e69259a-615b-4252-b3f8-53ecaeccb94a_3'. The device type stated in that event is 'deviceType': 'lightSensor'.
The ids look almost identical except for the last digit so it is clear it is coming from the Motion Sensor. Because it is a different id, the light_level attribute in the Motion Sensor class does not get filled.
In my own software, I would have to program it really as some dirty hack to work with this event for an unknown id. Because without this event everything fits perfectly in the Python classes.
Ah I think I understand, so what you are doing is you map your events, by the id, to the device?
Yes, in the event handler I have written, I look at the id ... then I look it up in all the ids I have received with get_all_devices call. And that device id in the event is not in that list ...
Furthermore, the characteristics of this particular event does not really fit a "Motion Sensor" (or any other current class of devices).
I have made it work by just a couple of dirty hacks, but I wonder how the right way forward is. Especially if IKEA starts creating new devices with combined functionalities. Or when IKEA just creates a light sensor as separate device (which does not sound too strange actually).
So just curious if "we" are interested in handling this strange combination case gracefully of just let it go as it goes.