Light control based upon motion, time of day and luminance

Hello all

]I have been asked that i should put this question as a new thread.

I tried to trigger the flow based on time in lieu of motion. At the moment it's not working

I have been tweaking my node red environment and i think i'm getting a very basic understanding on how to use it thanks to you all. Your patience and help is greatly appreciated.

11/30/2023, 12:10:27 PM[node: Light on 60%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg.payload : string[3]

"3.0"

The above is an output of my node red debug for one of my lights

I do not understand what the "3.0" is

furthermore as you see from this output the light brightness is supposed to be 60% however when i verify the status of the lightbulb on the shelly app , I see initially the light off (as it should be) then when motion is detected the light tuns on at 30%

The night setting is 20% therefore i do not know where this 30% comes from.

I went to the device web page and i see that the device is at 30%.

Since my native Home assistant works (regardless of the light native setting), I feel that it is my node red instance that is incorrectly configured

The motion detection works

it then the activity passes through a time range node and one output of the node is going to day time setting (light on 60%) and the second output of the time range node goes to night time setting (light on 20%)

as suggested here above i entered {“brightness_pct”:60} for the daytime option and {“brightness_pct”:20} for the night mode in the edit call service node.

I feel that i am missing something or parameter that will cause the override the shelly lightbulb settings

should the % value be in quotes (it does not look like it)

Thank you for your time patience and help

From the debug node i do not see where this error occurs

Thank you for any assistance

Hi not really understanding your issue, can we see an export of your flow, and your debug outputs for all the incoming sensors.

The below describes how to export property values from the debug, you can then post here in a copyable format.
There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

Thank you for your reply @E1cid

to clarify my issue, When the flow will invoke a call service node calles "Light on Day" It should turn on a shelly light at a brightness of 60% and when the flow invoke invokes "light on Night" it should turn on the shelly bulb at 20%. This is the objective / requirement. The flow should cause the light to turn on and set the brightness of the bulb (20%) and override the current state of brightness of the bulb.

The flow is made as follow

event state node=Motion detection: state if on, state type string connected to:
current state node = luminosity state below 5 state type number connected to
time range node = 07:00 to 22:00 connected to
Call service node = Shelly light turn on brightness 60% (20% if night)
I did not input/change msg payload in any node

12/3/2023, 8:20:30 AM[node: Motion Detected](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg : Object

object

payload: "on"

data: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

old_state: object

new_state: object

topic: "binary_sensor.multisensor_6_motion_detection"

_msgid: "a5aa2ab2fcffef14"

12/3/2023, 8:20:30 AM[node: Illuminance](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg.payload : number

0x2

12/3/2023, 8:20:30 AMLight on Nightsent data : msg :

object

domain: "light"

service: "turn_on"

data: object

device_id: "79672ab21f9ab0c866d2d8a2259e60ac"

12/3/2023, 8:20:30 AM[node: Light on 20%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg.payload : number

2

I apologise for my ignorance but I just copied, pasted and justified the debug log. In this log I do not see where the flow tells the light at what brightness it should be.
Hope this helps

Once again thank you for taking the time to respond and for your patience and help

Hi @wbravin, I apologise for my ignorance too but Home Assistant seems to do some things very differently to Node-red. I only use Node-red.

On top of that, all I know about your code is the one or two debug node outputs you have posted.
If I had a screen capture of the editor I could put your questions into some context.
If I had an export of the flow (which @E1cid asked you for) it might help even more, though the HomeAssistant specific nodes would mean nothing to me.

Given the above, all I can do is to try and answer the first bit of your question.

"3.0" is the value contained in msg.payload. In this case it is a string not a number.

The debug message you first posted is made up like this:

The time this message was created: 11/30/2023, 12:10:27 PM
See notes below: [node: Light on 60%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection :
The payload datatype: msg.payload : string[3]
The payload value: "3.0"

Notes.
In vanilla Node-red this would be msg.topic. It looks like HomeAssistant is manipulating this to include the name of the node which originated this message "Light on 60%", some sort of internally significant URL and then " binary_sensor.multisensor_6_motion_detection" which may be msg.topic.

Thank you @jbudd for this explanation

I have a debug node on all the nodes of the flow

12/3/2023, 11:01:49 AM[node: Motion Detected](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg : Object

object

payload: "on"

data: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

old_state: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

state: "off"

attributes: object

device_class: "motion"

friendly_name: "Entrance Hall Sensor Motion detection"

last_changed: "2023-12-03T09:42:24.420748+00:00"

last_updated: "2023-12-03T09:42:24.420748+00:00"

context: object

id: "01HGQGXFD48ZPKD07Q4PK2MY1N"

parent_id: null

user_id: null

new_state: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

state: "on"

attributes: object

device_class: "motion"

friendly_name: "Entrance Hall Sensor Motion detection"

last_changed: "2023-12-03T10:01:49.741645+00:00"

last_updated: "2023-12-03T10:01:49.741645+00:00"

context: object

id: "01HGQJ11DDVPPS082SABPF82BQ"

parent_id: null

user_id: null

timeSinceChangedMs: 6

topic: 0

_msgid: "af8ced566cdb4a9e"

12/3/2023, 11:01:49 AM[node: Illuminance](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

87

12/3/2023, 11:01:49 AMLight on Daysent data : msg :

object

domain: "light"

service: "turn_on"

data: object

area_id: "entrance_hall"

device_id: "79672ab21f9ab0c866d2d8a2259e60ac"

entity_id: "light.shelly_shbduo_1_98cdac2ba9b9"

12/3/2023, 11:01:50 AM[node: Time of Day](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.Time of day : undefined

undefined

12/3/2023, 11:01:50 AM[node: Light on 10%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

87

The IP of node light on 10% is the ip of the Home assistant

I can follow the motion node with the payload "on"

The Illuminance node has a msg payload of 87 i do not know where this comes from

The time of day node shows a payload of undefined

and the light on shows a msg payload of number 87

I do feel that my lack of knowledge of node red is preventing me from developing such a simple flow.

I am truly sorry for causing you all to take up so much of your time.

I also thank you for this an all the teaching and help given

@wbravin

If you want better help, please use the tools at your disposal.

As @E1cid stated earler, PLEASE use the Copy Value button on the debug when copying data.

1 Like

This is a picture of one of my flows. It is not relevant to your question.
image

I feel that your failure to respond to questions is preventing us from helping you.
Where is the picture of your flow?
Where is the export of your flow?

1 Like

Screenshot 2023-12-03 121836|690x242

flows (3).json (15.3 KB)

Sorry I thought i was.... Here are the flow export and the picture of my flow

I truly hope this is what you are requesting

Thank you for your patience

I do not know how the HA nodes work, but let's imagine the motion sensor detects movement.
A message goes to the illuminance node.

  • Does it pass straight through?

  • Does it pass through only if the light level is below a certain level?

  • Or is it blocked?

  • Does the illuminance node also create a new message when the light level goes above/below the trigger level?

  • I see it has two outputs. What's the significance of the second unconnected one?

Next comes the time range switch node.
Like the Home Assistant nodes, this is unfamiliar to me but I assume it routes the message to one of it's two outputs according to the time of day.

  • Can this node also create a new message eg at 18:00?

And finally we have the call service nodes to turn lights on or off.

If something triggers the motion sensor, you should be able to track the message through your flow by means of the debug nodes at each step.

  • Does it reach the "Light on" debug nodes?
  • What format message does the light need to turn on?
  • Does the message you are sending match this format?

Just for your information, here is what a Home Assistant flow looks like when it is imported into Node-red.
Perhaps this explains why this forum sometimes seems unhelpful with HA problems. Literally all we can tell about those unknown nodes is that there is something there.

Thank you for your quick response

As outlined in the flow the does go to full completion in both timeframes.

If i set the light level of the bulb in the shelly app the flow will turn on the light at the bulb setting and not as the prescribed 60 or 20% (this is my issue).

As far as I can see the luminance level is a set condition on which to trigger and continue the flow.

I am definitely to inexperienced to identify if the illuminance node changes the message. As far as i see it it only acts as a threshold

In the time range node I interpreted it as being the top level true (within day time) and the lower connection would be false for all event outside the day time range . Therefore night shift. I do not know it it creates a message IMHO i think it only is setting the parameters for day and night. In the debug node i do not see any evidence of any new or additional message.

Just to mention yesterday the flow was divided in 2 separate flows one for day and one for night.

I had the same issue with both of these

At least this is my understanding
I just tested the sequence and here is a copy of the debug nos for the flow

12/3/2023, 3:19:08 PM[node: Motion Detected](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg : Object

object

payload: "on"

data: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

old_state: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

state: "off"

attributes: object

device_class: "motion"

friendly_name: "Entrance Hall Sensor Motion detection"

last_changed: "2023-12-03T12:26:43.080121+00:00"

last_updated: "2023-12-03T12:26:43.080121+00:00"

context: object

id: "01HGQTAB08DZTGEV0VFCGSPGC1"

parent_id: null

user_id: null

new_state: object

entity_id: "binary_sensor.multisensor_6_motion_detection"

state: "on"

attributes: object

last_changed: "2023-12-03T14:19:08.161314+00:00"

last_updated: "2023-12-03T14:19:08.161314+00:00"

context: object

timeSinceChangedMs: 3

topic: 0

_msgid: "583399c1b4cf48f7"

12/3/2023, 3:19:08 PM[node: Illuminance](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

8

12/3/2023, 3:19:08 PMLight on Daysent data : msg :

object

domain: "light"

service: "turn_on"

data: object

area_id: "entrance_hall"

device_id: "79672ab21f9ab0c866d2d8a2259e60ac"

entity_id: "light.shelly_shbduo_1_98cdac2ba9b9"

12/3/2023, 3:19:08 PM[node: Time of Day](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.Time of day : undefined

undefined

12/3/2023, 3:19:08 PM[node: Light on 60%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

8

The light did turn on (by coincidence it was set at 60%) at 60% and after the set time it did turn off

as far as i understand as long as the motion detection sensor is on
the luminance and the time are on conditions to be met in order to turn on the light.

I do not know what message is required by the bulb for the luminance to be overridden..
In the home assistant automation I do not need to set, send. or input any additional parameters

Thank you for your help

Hey @wbravin

Just a reminder - please remember to use the "Copy Value" button as you have been asked 3 times now :person_shrugging:

I find it hard to understand the debug stuff you have posted.
Have you copied and pasted it from the debug pane?
It does not resemble the debug output I see in my Node-red editor, the double spacing does not help.

Looking at your flow diagram I would expect it to turn on at the brightness set in your Light on Day or Light on Night nodes.

  • When the lights turn on at 20% but because of the time you would expect 60%, which of the Light on debug nodes is triggered?

This is what you get when you copy from the debug panel by directly highlighting text. And why we've asked 3 times for the op to use the copy value button.

{"payload":"on","data":{"entity_id":"binary_sensor.multisensor_6_motion_detection","old_state":{"entity_id":"binary_sensor.multisensor_6_motion_detection","state":"off","attributes":{"device_class":"motion","friendly_name":"Entrance Hall Sensor Motion detection"},"last_changed":"2023-12-03T17:13:09.887469+00:00","last_updated":"2023-12-03T17:13:09.887469+00:00","context":{"id":"01HGRAPTZZZ561DWGN10C1GTTT","parent_id":null,"user_id":null}},"new_state":{"entity_id":"binary_sensor.multisensor_6_motion_detection","state":"on","attributes":{"device_class":"motion","friendly_name":"Entrance Hall Sensor Motion detection"},"last_changed":"2023-12-03T17:29:44.013676+00:00","last_updated":"2023-12-03T17:29:44.013676+00:00","context":{"id":"01HGRBN5TDNNVS5PPTZFJ5K3MA","parent_id":null,"user_id":null},"timeSinceChangedMs":2}},"topic":0,"_msgid":"0f47fd02d2c63f08"}

Time of day

12/3/2023, 6:29:44 PMLight on Daysent data : msg :

object

domain: "light"

service: "turn_on"

data: object

area_id: "entrance_hall"

device_id: "79672ab21f9ab0c866d2d8a2259e60ac"

entity_id: "light.shelly_shbduo_1_98cdac2ba9b9"

12/3/2023, 6:29:44 PM[node: Time of Day](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.Time of day : undefined

undefined

12/3/2023, 6:29:44 PM[node: Light on 60%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

0

for the motion detection portion i followed @Steve-Mcl instruction but only the motion detection node gave me this option. Furthermore I tried to ctrl +e this section however i did not see it formatted properly

The illuminance and the time range node did not offer this option.

For the call service node I exploded it and copy and pasted here above

@Steve-Mcl sir, \I truly apologize however this is the extent of my knowledge

Thank you for your help and patience

1 Like

Hello all

Just to let you know that this issue is nor solved

All remained identically as before with the exception of the call service node called turn on light in the configuration of this node specifically in the data field where one puts {"brightness_pct":value}
the data type should be set to {} JSON and not to expression

This made my simple flow work on the test environment, tonight i will try it live

Thank you all for you very much for your patience help and teachings

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.