Set a new template for light

hi there,

I am looking for a way to implement a second template for a light.
I installed a shelly dimmer in my corridor for the lights.
With node red I created a flow to turn on the lights, if occupancy was detected.
After 45 sec the light should turn off, if no occupancy was detected.
This works.

But now I want to integrate a second flow, which turns the lights off after 5 min, if someone pushes the light button.
The problem is that the flow turns off the lights 45 sec after no occupancy was detected.

Is it possibel to create a sensor template with a new light (friendly name) to separate this two flows?

I tried to write a yaml code for the corridor light, but I don’t know, how I can integrate the “light.deckenlampe_flur” to this code (if this code is correct?):

#Flur Lampe Bewegung
  - platform: template
    sensors:
    flur_lampe_bewegung:
      friendly_name: Flur Lampe Bewegung
      ????

Use the light switch to send a message to the 45 second trigger node extending the time to 5 min or 300000ms. Nodered uses milliseconds for time.

[{"id":"d1396b9e.b1f128","type":"server-state-changed","z":"d6a46901.ebee1","name":"light switch on","server":"6b1110b5.183a4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"","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,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":1040,"wires":[["93efedd9.49a8f"],[]]},{"id":"93efedd9.49a8f","type":"change","z":"d6a46901.ebee1","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"300000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":1040,"wires":[["85faf1b4.dec9c"]]},{"id":"85faf1b4.dec9c","type":"trigger","z":"d6a46901.ebee1","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"45","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":770,"y":1040,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Hi there!

I’m not sure if the other guy answered your question so I made two automations for you, keep in mind you will have to change some things to fit your specific sensors information along with the correct light for your use case

A automation for turning the light on with motion

alias: Turn Light On With Motion
description: ''
mode: single
trigger:
  - platform: state
    entity_id: sensor.motion
    from: No Motion
    to: Motion
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.light

A automation for turning the light off when there is no motion for 45 seconds

alias: Turn light off when there is no motion for 45 seconds
description: ''
trigger:
  - platform: state
    entity_id: sensor.motion
    from: Motion
    to: No Motion
    for: '00:00:45'
condition: []
action:
  - service: light.turn_off
    target:
      entity_id: light.light
mode: single
1 Like

thanks for your ideas.

But the problem is a little bit difficult…
The motion flow works.

But if someone use the light button, the 45s of the motion flow reacts due the reason that the entity is the same:

So i thought, if I create a second entity (with an other friendly name / template sensor) I can use both of those flows with two different times.

If you add the change node I posted connected like so. When the switch goes on the timer changes to 5 minutes instead of 45 seconds.

1 Like

Okay, but I think that the 45 s trigger starts, if the “Tag/Nacht” (day/night) action starts, or rather the entities of these states…

I believe what you want is that when you push the button, then the light will only turn off if no motion is detected for 5 minutes

when you push it again, revert back to the previous, light will only turn off when no motion is detected over 45 seconds

Am I right?

Could you post your flow please? the code?

1 Like

You got it almost.

If I push the button, the light should turn on for 5min and after that it goes off.
If within 5min someone push the button again, it should turns off and will react to motion (on goes off if no motion detects within 45 s)

Here is the current code:


[{"id":"af7416ee.37c178","type":"tab","label":"Deckenlampe Flur","disabled":false,"info":""},{"id":"1c73597d.5bfbdf","type":"switch","z":"af7416ee.37c178","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":200,"wires":[["cb6dcae0.000078"],["bff73bf3.6b1518"]]},{"id":"94211752.509d4","type":"api-call-service","z":"af7416ee.37c178","name":"Tag ","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1410,"y":40,"wires":[["bff73bf3.6b1518"]]},{"id":"20686e7d.bb3402","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.deckenlampe_flur","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1450,"y":360,"wires":[[]]},{"id":"bff73bf3.6b1518","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"45","extend":false,"overrideDelay":false,"units":"s","reset":"true","bytopic":"all","topic":"topic","outputs":1,"x":1130,"y":300,"wires":[["20686e7d.bb3402"]]},{"id":"5f545cca.2c7614","type":"trigger-state","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.flur_bewegungsmeldung_occupancy","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"bool","comparatorValue":"true","propertyValue":"new_state.state"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"bool","comparatorValue":"false","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"habool","x":290,"y":200,"wires":[["1c73597d.5bfbdf"],["1c73597d.5bfbdf"]]},{"id":"fb93c45b.161b9","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":380,"y":440,"wires":[["a5ad5640.15adc"]]},{"id":"cb6dcae0.000078","type":"time-range-switch","z":"af7416ee.37c178","name":"Tag 6:30-23:00","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":1120,"y":80,"wires":[["9fb2b808.a5a8b8"],["69b2e451.820ab4"]]},{"id":"69b2e451.820ab4","type":"api-call-service","z":"af7416ee.37c178","name":"Nacht","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1410,"y":160,"wires":[["bff73bf3.6b1518"]]},{"id":"3ae1175c.893398","type":"api-call-service","z":"af7416ee.37c178","name":"Tag ","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.flur_deckenlampe","data":"{\"brightness_pct\":100}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":770,"y":380,"wires":[[]]},{"id":"679b5aff.b6b4dc","type":"api-call-service","z":"af7416ee.37c178","name":"Nacht","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.flur_deckenlampe","data":"{\"brightness_pct\":30}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":770,"y":500,"wires":[[]]},{"id":"a5ad5640.15adc","type":"time-range-switch","z":"af7416ee.37c178","name":"Tag 6:30-23:00","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":580,"y":440,"wires":[["3ae1175c.893398"],["679b5aff.b6b4dc"]]},{"id":"d90859a9.395268","type":"server-state-changed","z":"af7416ee.37c178","name":"Deckenlampe Flur","server":"818794df.29c548","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.deckenlampe_flur","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":440,"wires":[["fb93c45b.161b9"],[]]},{"id":"9fb2b808.a5a8b8","type":"api-current-state","z":"af7416ee.37c178","name":"< 30 lx","server":"818794df.29c548","version":2,"outputs":2,"halt_if":"30","halt_if_type":"num","halt_if_compare":"lt","entity_id":"sensor.flur_bewegungsmeldung_illuminance","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1290,"y":60,"wires":[["94211752.509d4"],[]]},{"id":"818794df.29c548","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

That button is a physical button in the lamp itself, right? Don’t you get any event in HA from pushing that button? or something?

When somebody pushes that button, is the lamp already turned on due to the motion sensor?

1 Like

It is a normal wall toggle, which is connected with a Shelly dimmer.

In some cases the corridor light turns off, if a person sits in the corridor and don’t move :grin:

Also I got a bug with the Lux sensor, which also turns off the light because the lux is higher than in the flow described (<30lx)(you can see it at the right upper corner)

I have this so far but this flow requires some event coming from pushing that button in the lamp

[{"id":"feffeba4.4b1c08","type":"server-state-changed","z":"af7416ee.37c178","name":"PIR","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.flur_bewegungsmeldung_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":210,"y":800,"wires":[["b34bd13b.761b2","57e28f0a.f9f7a"]]},{"id":"57e28f0a.f9f7a","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"45","extend":false,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":370,"y":840,"wires":[["d918883f.76fb78"]]},{"id":"eb7b93b5.e2c79","type":"api-call-service","z":"af7416ee.37c178","name":"Tag ","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":770,"y":700,"wires":[[]]},{"id":"f5f9e195.48d0c","type":"time-range-switch","z":"af7416ee.37c178","name":"Tag 6:30-23:00","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":480,"y":760,"wires":[["726c67b6.db13b8"],["5cb31285.062c9c"]]},{"id":"5cb31285.062c9c","type":"api-call-service","z":"af7416ee.37c178","name":"Nacht","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":650,"y":780,"wires":[[]]},{"id":"726c67b6.db13b8","type":"api-current-state","z":"af7416ee.37c178","name":"< 30 lx","server":"818794df.29c548","version":2,"outputs":2,"halt_if":"30","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.flur_bewegungsmeldung_illuminance","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":720,"wires":[["eb7b93b5.e2c79"],[]]},{"id":"b34bd13b.761b2","type":"switch","z":"af7416ee.37c178","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":315,"y":760,"wires":[["f5f9e195.48d0c"]],"l":false},{"id":"32f0af3e.fd946","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.deckenlampe_flur","data":"","dataType":"jsonata","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":770,"y":840,"wires":[[]]},{"id":"d918883f.76fb78","type":"switch","z":"af7416ee.37c178","name":"Input != off?","property":"input","propertyType":"flow","rules":[{"t":"neq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":840,"wires":[["32f0af3e.fd946"]]},{"id":"4e50c4eb.a8212c","type":"inject","z":"af7416ee.37c178","name":"BUTTON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":940,"wires":[["578531c8.5720a"]]},{"id":"578531c8.5720a","type":"change","z":"af7416ee.37c178","name":"Input off","rules":[{"t":"set","p":"input","pt":"flow","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":940,"wires":[["f5f9e195.48d0c","2dd86690.73422a"]]},{"id":"2dd86690.73422a","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"300","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":560,"y":940,"wires":[["359e1fcd.c2a23"]]},{"id":"359e1fcd.c2a23","type":"change","z":"af7416ee.37c178","name":"Input on","rules":[{"t":"set","p":"input","pt":"flow","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":940,"wires":[["32f0af3e.fd946"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true},{"id":"818794df.29c548","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Thanks for that code
I will test it tomorrow :slight_smile:

Get it again, I updated it.

No problem. I’ve never had any sonoff/shelly or whatever but common sense tells me you must receive some sort of event from pushing the physical button. It may not though… If you get that event, just replace the “BUTTON” node with the event of your button.

1 Like

I forgot this

If whithin 5 minutes someone pushes the button again, should the light turn off? If so, this flow is correct I believe.

final flow

[{"id":"910accce.60601","type":"server-state-changed","z":"26a8be47.ed6452","name":"PIR","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.flur_bewegungsmeldung_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":270,"y":1480,"wires":[["4e8796c4.f8a9c8","77896491.a8b1ac"]]},{"id":"77896491.a8b1ac","type":"trigger","z":"26a8be47.ed6452","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"45","extend":false,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":1520,"wires":[["80eabae3.7f9538"]]},{"id":"492a5f60.09de5","type":"api-call-service","z":"26a8be47.ed6452","name":"Tag ","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":830,"y":1380,"wires":[[]]},{"id":"d034d5dd.5fadc8","type":"time-range-switch","z":"26a8be47.ed6452","name":"Tag 6:30-23:00","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":540,"y":1440,"wires":[["513dfff9.cff84"],["7d99e7c9.90a9f8"]]},{"id":"7d99e7c9.90a9f8","type":"api-call-service","z":"26a8be47.ed6452","name":"Nacht","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":710,"y":1460,"wires":[[]]},{"id":"513dfff9.cff84","type":"api-current-state","z":"26a8be47.ed6452","name":"< 30 lx","server":"818794df.29c548","version":2,"outputs":2,"halt_if":"30","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.flur_bewegungsmeldung_illuminance","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":710,"y":1400,"wires":[["492a5f60.09de5"],[]]},{"id":"4e8796c4.f8a9c8","type":"switch","z":"26a8be47.ed6452","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":375,"y":1440,"wires":[["d034d5dd.5fadc8"]],"l":false},{"id":"bfed6b40.ee2df8","type":"api-call-service","z":"26a8be47.ed6452","name":"","server":"818794df.29c548","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.deckenlampe_flur","data":"","dataType":"jsonata","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":830,"y":1520,"wires":[[]]},{"id":"80eabae3.7f9538","type":"switch","z":"26a8be47.ed6452","name":"Input != off?","property":"input","propertyType":"flow","rules":[{"t":"neq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":590,"y":1520,"wires":[["bfed6b40.ee2df8"]]},{"id":"b8726b0f.32d7a8","type":"inject","z":"26a8be47.ed6452","name":"BUTTON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":1640,"wires":[["5959f7da.ae0f58"]]},{"id":"c477f9fa.19f0e8","type":"change","z":"26a8be47.ed6452","name":"Input off","rules":[{"t":"set","p":"input","pt":"flow","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1620,"wires":[["d034d5dd.5fadc8","a25b33bd.1ae3c"]]},{"id":"a25b33bd.1ae3c","type":"trigger","z":"26a8be47.ed6452","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"300","extend":true,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":650,"y":1620,"wires":[["16012ae1.45a605"]]},{"id":"16012ae1.45a605","type":"change","z":"26a8be47.ed6452","name":"Input on","rules":[{"t":"set","p":"input","pt":"flow","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":1620,"wires":[["bfed6b40.ee2df8"]]},{"id":"5959f7da.ae0f58","type":"switch","z":"26a8be47.ed6452","name":"Input?","property":"input","propertyType":"flow","rules":[{"t":"neq","v":"off","vt":"str"},{"t":"neq","v":"on","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":290,"y":1640,"wires":[["c477f9fa.19f0e8"],["9b171191.d9145"]]},{"id":"9b171191.d9145","type":"change","z":"26a8be47.ed6452","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1660,"wires":[["a25b33bd.1ae3c"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true},{"id":"818794df.29c548","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Hi,

This is a solution I’m also looking for,

Your previous one looks really good but it does not work exactly.

After turning off the power supply, the lamp turns off and on several times

I saw on another site the following solution and it also works partially maybe will give you an idea

Thank you for your help!


[{"id":"2713061b.7372ea","type":"group","z":"41ba209a.4e2858","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["e433ab36.c6b358","cd7df0e2.ea938","16bf9a80.ccead6","14739080.90dc9","ce4419ce.841178","279d7f80.57b5d","a2d4c1a6.bb35a","80d2d7f9.fc38d8","f5d9ef3a.7317a","a95d016e.6a5228"],"x":14,"y":39,"w":1652,"h":242},{"id":"e433ab36.c6b358","type":"api-call-service","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"Kitchen Ceiling Lights ON","server":"f22f6e73.21e16","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.fibaro_system_fgs222_double_relay_switch_2x1_5kw_switch_5","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1530,"y":140,"wires":[[]]},{"id":"cd7df0e2.ea938","type":"trigger","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"5min","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1150,"y":240,"wires":[["16bf9a80.ccead6"]]},{"id":"16bf9a80.ccead6","type":"api-call-service","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"Kitchen Ceiling Lights OFF","server":"f22f6e73.21e16","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.fibaro_system_fgs222_double_relay_switch_2x1_5kw_switch_5","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1520,"y":240,"wires":[[]]},{"id":"14739080.90dc9","type":"change","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":835,"y":240,"wires":[["cd7df0e2.ea938"]],"icon":"node-red/timer.svg","l":false},{"id":"ce4419ce.841178","type":"trigger-state","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"Kitchen Light Switch","server":"f22f6e73.21e16","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"switch.fibaro_system_fgs222_double_relay_switch_2x1_5kw_switch_5","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":140,"y":140,"wires":[["a2d4c1a6.bb35a"],[]]},{"id":"279d7f80.57b5d","type":"change","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"ENABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":595,"y":240,"wires":[["56668319.4c687c","14739080.90dc9"]],"icon":"font-awesome/fa-toggle-on","l":false},{"id":"a2d4c1a6.bb35a","type":"change","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"DISABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":575,"y":140,"wires":[["56668319.4c687c","14739080.90dc9"]],"icon":"font-awesome/fa-toggle-off","l":false},{"id":"80d2d7f9.fc38d8","type":"server-state-changed","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"Kitchen Ceiling Lights","server":"f22f6e73.21e16","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.fibaro_system_fgs222_double_relay_switch_2x1_5kw_switch_5","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,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":240,"wires":[["279d7f80.57b5d"],[]]},{"id":"f5d9ef3a.7317a","type":"api-current-state","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"Still Motion?","server":"f22f6e73.21e16","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.presence_5","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1230,"y":140,"wires":[["e433ab36.c6b358"],[]]},{"id":"a95d016e.6a5228","type":"comment","z":"41ba209a.4e2858","g":"2713061b.7372ea","name":"
 !","info":"","x":280,"y":80,"wires":[],"icon":"node-red/bluetooth.png"},{"id":"f22f6e73.21e16","type":"server","name":"yuval_Home Assistant","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]



1 Like

It’s not pretty but it should do what you ask. Switch on activates stop on traffic node. 5 minute timer OR off command from switch, clears triggers and opens traffic node.

[{"id":"910accce.60601","type":"server-state-changed","z":"35b293a2.b5aafc","name":"PIR","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.flur_bewegungsmeldung_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":770,"y":940,"wires":[["4e8796c4.f8a9c8","77896491.a8b1ac"]]},{"id":"77896491.a8b1ac","type":"trigger","z":"35b293a2.b5aafc","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"45","extend":false,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":930,"y":980,"wires":[["70e7a2bd.487454"]]},{"id":"492a5f60.09de5","type":"api-call-service","z":"35b293a2.b5aafc","name":"Tag ","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"json","mergecontext":"","mustacheAltTags":false,"output_location":"payload","output_location_type":"msg","x":1330,"y":840,"wires":[[]]},{"id":"d034d5dd.5fadc8","type":"time-range-switch","z":"35b293a2.b5aafc","name":"Tag 6:30-23:00","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":1040,"y":900,"wires":[["513dfff9.cff84"],["7d99e7c9.90a9f8"]]},{"id":"7d99e7c9.90a9f8","type":"api-call-service","z":"35b293a2.b5aafc","name":"Nacht","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"json","mergecontext":"","mustacheAltTags":false,"output_location":"payload","output_location_type":"msg","x":1210,"y":920,"wires":[[]]},{"id":"513dfff9.cff84","type":"api-current-state","z":"35b293a2.b5aafc","name":"< 30 lx","server":"","version":2,"outputs":2,"halt_if":"30","halt_if_type":"num","halt_if_compare":"lt","entity_id":"sensor.flur_bewegungsmeldung_illuminance","state_type":"str","blockInputOverrides":false,"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1210,"y":860,"wires":[["492a5f60.09de5"],[]]},{"id":"4e8796c4.f8a9c8","type":"switch","z":"35b293a2.b5aafc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":875,"y":900,"wires":[["d034d5dd.5fadc8"]],"l":false},{"id":"bfed6b40.ee2df8","type":"api-call-service","z":"35b293a2.b5aafc","name":"","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.deckenlampe_flur","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"output_location":"payload","output_location_type":"msg","x":1410,"y":1040,"wires":[[]]},{"id":"b8726b0f.32d7a8","type":"inject","z":"35b293a2.b5aafc","name":"BUTTON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":1000,"wires":[["2fd656bc.f2c66a"]]},{"id":"a25b33bd.1ae3c","type":"trigger","z":"35b293a2.b5aafc","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"300","extend":true,"overrideDelay":true,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":950,"y":1140,"wires":[["fd79ee98.40cfb8","bfed6b40.ee2df8","a443a0d0.5b90f8"]]},{"id":"70e7a2bd.487454","type":"traffic","z":"35b293a2.b5aafc","name":"","property_allow":"payload","filter_allow":"release","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"hold","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":true,"x":1190,"y":980,"wires":[["bfed6b40.ee2df8"]]},{"id":"2fd656bc.f2c66a","type":"switch","z":"35b293a2.b5aafc","name":"on/off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":1040,"wires":[["5999664a.a65a6","a25b33bd.1ae3c"],["a443a0d0.5b90f8","fd79ee98.40cfb8","bfed6b40.ee2df8"]]},{"id":"5999664a.a65a6","type":"change","z":"35b293a2.b5aafc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"hold","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":1020,"wires":[["70e7a2bd.487454"]]},{"id":"fd79ee98.40cfb8","type":"change","z":"35b293a2.b5aafc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"release","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":1080,"wires":[["70e7a2bd.487454"]]},{"id":"a443a0d0.5b90f8","type":"change","z":"35b293a2.b5aafc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1140,"wires":[["77896491.a8b1ac","a25b33bd.1ae3c"]]}]

2 Likes

understood :slight_smile:
But one thing I dont understand:
what can I use to remove the button from the code and use the physical button in the wall?
the button toggles the shelly (light.deckenlampe_flur).

So my idea was, if I create a separate template sensor in my config yaml, which also toggles the shelly so I have two different entities in this flow and have not the problem, if the “button” entity changes the state to on the trigger from the motion also starts.

Like this:
If I hit the switch in the corridor, the entity “light.deckenlampe_flur_manual” turns on the light.
If motion was detected the flow turns on the “light.deckenlampe_flur_flow”.
But both entities are the same light / shelly…

Is the shelly intregated through mqtt?

Don’t you receive an mqtt event when you push the physical button?

When you hit the switch in the corridor, is the light already turned on due to motion detection?

I don’t use mqtt.

If the Lux is higher than 30 the Motion don’t toggle the light on.

I want that the light will be 5 min on, if I toggle the switch manually :sweat_smile:

Do this, put the switch entity in an events: state node then connect that to a debug node. Deploy, open the debug panel on the right, press the button several times and post what appears in the debug panel.

1 Like