Trådfri motion sensor and toilet lights during night time

Hi,

In my bathroom I have IKEA Trådfri bulbs and a Trådfri motion sensor.
I want this:

23:00 - 05:30 When I enter the bathroom the lights should only be at 1%
05:31 - If I enter after this the lights go on with 100%.

I´ve played around with scenes and automations but It gets messy and I dont know how to write scripts.

What do I do? Thanks in advance

I used node red for exactly that (except it is for my hallway, not toilet)

[{"id":"250d5853.dcd458","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4a201612.4bf768","type":"mqtt in","z":"250d5853.dcd458","name":"Motion Hallway Upstairs","topic":"zigbee2mqtt/MotionHallwayUpstairs","qos":"2","datatype":"auto","broker":"f90cfe3b.a8bd7","x":160,"y":80,"wires":[["41b828c6.4777e8"]]},{"id":"b5a6b1b5.61ea3","type":"function","z":"250d5853.dcd458","name":"Turn on 1%","func":"if ( msg.payload.includes(\"\\\"occupancy\\\":true\"))\n{\n    msg.payload = {\n        domain: \"light\",\n        service: \"turn_on\",\n        data: {\n            entity_id: \"light.light_hallway_upstairs\",\n            \"brightness_pct\": 1\n        }\n    };\n}\nelse\n{\n    msg.payload = \"do nothing\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":140,"wires":[["92816d41.91995","acb7a1f2.f664f"]]},{"id":"275f91b6.a6a3ae","type":"api-call-service","z":"250d5853.dcd458","name":"payload light","server":"37d68302.2aabcc","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1150,"y":180,"wires":[[]]},{"id":"f5741134.765c7","type":"delay","z":"250d5853.dcd458","name":"Delay massage","pauseType":"delayv","timeout":"10","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":140,"wires":[["c767682a.d19b98"]]},{"id":"c767682a.d19b98","type":"function","z":"250d5853.dcd458","name":"Turn off","func":"msg.payload = {\n    domain: \"light\",\n    service: \"turn_off\",\n    data: {\n        entity_id: \"light.light_hallway_upstairs\"\n    }\n};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1140,"y":140,"wires":[["275f91b6.a6a3ae"]]},{"id":"92816d41.91995","type":"function","z":"250d5853.dcd458","name":"Reset 10m Delay","func":"msg.delay = 600000;\nvar m1 = {reset:true};\nreturn [[m1,msg]];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":140,"wires":[["f5741134.765c7"]]},{"id":"acb7a1f2.f664f","type":"switch","z":"250d5853.dcd458","name":"Only turn on","property":"payload.service","propertyType":"msg","rules":[{"t":"cont","v":"turn_on","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":730,"y":180,"wires":[["275f91b6.a6a3ae"]]},{"id":"c13c465.3e1bfb8","type":"server-state-changed","z":"250d5853.dcd458","name":"","server":"37d68302.2aabcc","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.light_hallway_upstairs","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":520,"y":80,"wires":[["92816d41.91995"],[]]},{"id":"2f6f6520.67324a","type":"function","z":"250d5853.dcd458","name":"Turn on 10%","func":"if ( msg.payload.includes(\"\\\"occupancy\\\":true\"))\n{\n    msg.payload = {\n        domain: \"light\",\n        service: \"turn_on\",\n        data: {\n            entity_id: \"light.light_hallway_upstairs\",\n            \"brightness_pct\": 10\n        }\n    };\n}\nelse\n{\n    msg.payload = \"do nothing\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":180,"wires":[["acb7a1f2.f664f","92816d41.91995"]]},{"id":"41b828c6.4777e8","type":"time-range-switch","z":"250d5853.dcd458","name":"","lat":"51.83125","lon":"4.33552","startTime":"sunset","endTime":"sunrise","startOffset":"1","endOffset":0,"x":240,"y":160,"wires":[["b5a6b1b5.61ea3"],["2f6f6520.67324a"]]},{"id":"f90cfe3b.a8bd7","type":"mqtt-broker","z":"","name":"","broker":"hassio.aceindy.nl","port":"1883","clientid":"node-red","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"37d68302.2aabcc","type":"server","z":"","name":"Home Assistant"}]
1 Like

@aproposemil it doesn’t need to be messy. Are you using the Ikea gateway or a zigbee stick? In the following I assume you’re using a zigbee stick.

I have a similar setup in which the lights in my workshop comes on when I walk in. I’ve used the built-in OFF functionality of the sensor (which sends an OFF after a set number of minutes). In my setup I use the following but you should of course use your own entity names:
Bulb: light.verkstaden
Sensor: binary_sensor.rorelse_verkstaden

In the Lovelace UI go to Configuration -> Automations. Click on the orange circle with a plus sign in the lower right hand corner.

Give the automation a unique name:

Create a trigger:

Set up the condition for night time. It has to be two conditions as a single condition can’t span midnight. So we set up one for after 23.00 and one for before 05.30.

Set up the action to light the bulb (with 1% brightness):


NOTE: brightness has a range of 0-255 so 100% = 255 and 1% = 3.

Click on the orange circle to save the automation.

Repeat the above for the daytime action. As this will happen between two times in the same day you can use a single time condition with before 23:00:00 and after 05:30:00. Also, set brightness to 255.

Lastly you need to set the automation for turning OFF the light when the motion sensor reports OFF. Just add an automation like above but change the trigger to ‘off’ and the service called to “light.turn_off”. You do not need to use a condition.

Hope this helps!

1 Like

Haven´t learned node red yet. Is this possible when I use the trådfri gateway also?

Thanks for that reply. Is this possible when I use the trådfri gateway also since I don´t use conbee yet?

No. It is not possible. In the Trådfri ecosystem, the motion sensors are paired directly to the bulb, you can’t get binary_sensors from the motion detectors.

You don’t need a conbee, it can be done with any independent Zigbee coordinator : conbee (phoscon), Zigbee2Mqtt (cc25xx, cc26xx, conbee), ZHA (a lot of different sticks/coordinators available).

1 Like

Content deleted.

I´ve tried the way that @alvinger suggested, but as @francisp says, I can´t see the motion sensor in my entities. :frowning:

If you have made it work, please tell how.

I remember now, @francisp is correct, the Tradfri motion sensor is not visible in HA Core. Sorry about that.

Actually, I’m using another brand of motion sensor (Xiaomi Aqara) as the trigger device. That’s why it works for me.

I did try this Hack: IKEA Trådfri Motion Sensor for presence control but found that the Tradfri motion sensor is (used to be?) horribly slow in responding to movement.

Yes, using the Trådfri gateway means that you don’t get the events from the sensor into Home Assistant. But you can use the Trådfri app to set up the automation entirely in the Trådfri ecosystem.

You can still get the status of the bulb in Home Assistant and you can control it. But you can’t use the motion sensor as trigger.

I solved it the “messy way” with one automation to turn it on 1% and 5 seconds later turn it off in the evening and in the morning 100% and then 5 sec later turn it off. When I order the Zigbee stick I will change this. Thanks for your replies!

That depends on the context. As I wrote on my thread, I have decommissioned this solution in favor of CC2531 with zigbee2mqtt. That means that I read the motion sensor directly in HA.

My experience is that the Trådfri motion sensor is quick in responding to initial event (I have three at home) but slow in restoring back.

same same here…

btw zigbee2mqtt can also do bindings: