2024-04-16
md
Adding an IKEA VALLHORN Motion Sensor in Domoticz
<-Adding an IKEA Trådfri Shortcut Button in Domoticz
<-Passerelle Sonoff Zigbee Bridge (ZBBridge) avec Domoticz

The VALLHORN Sensor The last day of March was supposed to be the first day of income tax preparation. Procrastinating proved more appealing and the best strategy was to do a test installation of a new IKEA zigbee VALLHORN motion sensor type E2134 picked up about a month ago. There's a very high likelihood that the sensor will be moved. When that time comes, I will have forgotten everything; hence this post to document how it was done. So this is by no means an in-depth review of the sensor.

Tradfri EOLThe recently introduced VALLHORN motion sensor is probably meant to replace the older TRÅDFRI models: type E1745 and type E1525. These older models were not in the Halifax (Canada) IKEA store when I purchased the VALLHORN and can't be found in the online catalogue in Canada. The image to the left shows that the E1745 is currently (April 2, 2024) available in the USA, but presumably only until the stock is exhausted.

The new VALLHORN is big, relatively speaking. Its face is a rounded 71 x 71 mm square and it is 34.5 mm deep, 38.4 mm if the sensor is inserted into its mounting bracket. Because of the bigger size the sensor is powered by two AAA batteries instead of coin cells. It could result in longer periods between battery replacements although I will not be able to verify that because I do not have any of the older IKEA motion sensors.

VALLHORN Dimensions

The Blakadder description of the older sensors reveals that the new sensor adds illuminance level to the occupancy and battery percentage measurements. This is useful because the test installation consists of using the VALLHORN to turn on lights in a stairway as someone approaches if the light level is below a set threshold. The two three-way switches that turn the lights on or off from either stair landings are connected to a Shelly 1 with Tasmota firmware. When the light is turned on, a timer is set and after five minutes it automatically turns off the light. This is enabled in Domoticz, our home automation server. Thus, all the heavy lifting is done by the existing home automation system, the VALLHORN will just trigger existing routines. Of course, the sensor must be paired with the Zigbee coordinator of the home automation system which in our case is a Sonoff ZbBridge with ZigbeeToTasmota.

While the IKEA recommended Zigbee hub was not needed in this configuration, full functionality of the sensor may not be exploited. Presumably, one could set the threshold level for the 0x0006 On/Off cluster messages it sends to a paired light, the hub, or some other zigbee device or devices. The test installation will ignore such messages and our home automation system will use only three messages from the sensor once it is paired with the system's zigbee coordinator.

Zigbee attributeTypeZigbeeToTasmota message
Illuminancenon negative integer{"ZbReceived":{"0xB8BC":{"Device":"0xB8BC","Illuminance":20969,"Endpoint":3,"LinkQuality":55}}}
Occupancy0 or 1{"ZbReceived":{"0xB8BC":{"Device":"0xB8BC","Occupancy":1,"Endpoint":2,"LinkQuality":13}}}
BatteryPercentage0...100 {"ZbReceived":{"0xB8BC":{"Device":"0xB8BC","BatteryVoltage":2.7,"BatteryPercentage":90,"Endpoint":1,"LinkQuality":52}}}

The ZigbeeToTasmota messages shown above are actually the translation of the sensor Zigbee Messages done by the Tasmota software. These are visible in the Tasmota console of the ZbBridge.

Since the illuminance is only reported when it changes, values sent by the sensor must be stored by Domoticz. A user-defined variable seemed like the best way of doing this. The following screen capture shows how to get to the User variables settings page in the Domoticz web interface.

Adding a user variable

Adding a variable is done by specifying its name, type and intial value.

Adding a user variable

Then it is necessary to click on the Add button. Once that is done, the new variable will be added to the variables table at the top and a variable idx number will be assigned to it. In this case stair_illuminance was assigned the idx value 4.

I suppose one could add a (hidden) virtual light switch in Domoticz to take activate the stair lights, but there is already a virtual switch running the aforementioned Shelly 1. Instead another user variable, named stair_occupancy or whatever one prefers, was created. It was assigned idx 5.

The next step is to add Tasmota rules in the Zigbee coordinator. In my case, I appended three rules to Rule3.

rule3 +ON zbreceived#0xB8BC#Occupancy DO publish domoticz/in {"command":"setuservariable", "idx":5, "value":"%value%"} ENDON ON zbreceived#0xB8BC#Illuminance DO publish domoticz/in {"command":"setuservariable", "idx":4, "value":"%value%"} ENDON ON zbreceived#0xB8BC#BatteryPercentage DO publish domoticz/in {"idx":225,"nvalue":0, "svalue":"%value%"} ENDON

As can be seen these rules define MQTT messages published in response to the Zigbee message from the sensor. The MQTT messages all have the domoticz/in topic to which Domoticz is automatically subscribed by default if the MQTT Client Gateway is installed in the system's Hardware. This is a choice on my part, and HTTP requests sent directly to Domoticz could be used instead.

The third rule is to update a virtual percentage sensor added in Domoticz to display the battery level and to send out a notification if the level drops below say 60%. Its idx is 225.

The last part of the puzzle is a rather simple dzVents Lua script that will be triggered by any change in the stair_occupancy user variable.

--[[ Turn "stair_light" on when "stair_occupancy" > 1 and stair_illuminance < 4000 stair_light: switch idx 138, stair_occupancy: user-variable idx 5 and stair_illuminance: user-variable idx 4 ]] return { on = { variables = { 5 } }, execute = function(dz, variable) if ( (variable.value > 0) and (dz.variables(4).value < 4000) ) then dz.devices(138).switchOn() end end }

I think the logic here is pretty clear. The execute function will be executed (of course!) whenever the value of variable 5 changes. If that value is greater than one, that means that the detector sensed motion as someone is approached the stairs. In that case the stair light is switched on as long as the illuminance is below the 4000 threshold.

Notes or random information and ideas.