Call state for binary sensor

Hello everyone,

I’m currently working on using Node-RED to control the state of a motion sensor. I’ve successfully achieved this in Home Assistant’s Developer Tools, but I’m encountering difficulties when attempting to do the same in Node-RED using the “Call Service” node.

The entity I’m targeting is identified as “binary_sensor.lock.”

I’ve experimented with various combinations of the service (e.g., “homeassistant.turn_on”) and JSON data (e.g., {"entity_id":"binary_sensor.lock","state":"on"}), but none seem to work.

Any guidance or suggestions on how to make this work would be greatly appreciated. Thank you for your assistance.

When doing it in the HA Developer Tools, then click the “Go to YAML mode” button.
It will give you the YAML view and from there it is a lot easier to fill out the call service node.

1 Like

thank you - i can’t seem to get the binary sensor to change at all using yaml mode under service. I can only do it under state. but i can’t see how it’s doing it i.e the direct call. odd

Unless I am mistaken, services in HA are there to allow control over ‘output’ or writable devices / entities only.

Binary_sensors are entities specifically created by integrations to represent an external device (binary) state, they should not be modified other than by the creating integration, and are not supported by the call service operation. Indeed, the documentation suggests that binary_sensors integration cannot be directly used.

https://www.home-assistant.io/integrations/binary_sensor/

Inputs, which are specifically there for users to change via the dashboard or services, include binary switches, and there are associated service calls for turning on / off / toggle.

I think the basic answer is - you can’t. Suggestion is to create an input-switch (binary) and update this both from your binary_sensor and from another means via a service call. Quite what this will then represent is a bit of a question, and does beg the question ‘why?’

If you are thinking that updating the binary_sensor will update the state of the device it monitors, it won’t. These are read only. The developer ‘state’ tool is only there to allow development testing, and is, I believe, the only way to change a binary_sensor (and only for ‘testing’, and does not hold the state value anyway).

I have to say I do like the idea of controlling the state of a motion sensor. Does making this ‘true’ mean that people suddenly walk past my camera?!

1 Like

I like the work backwards approach, set the sensor value and let the reality follow it :slight_smile:

Joke aside, sensors are managed by some other systems, so, even setting on developer tools would be transient depending on which integration is managing it. Input helper is way to go.

lol yep making it true means someone must be there :slight_smile:

i’m jsut trying to find a way to get google home to run a routine i.e from a switch that is triggered within home assistant.

i dont’ care if it’s a binary sensor or not but a switch i can’t seem to use to invoke the routine in google home

You can expose an input helper to google home and act on it as if it is a switch on google home side.

I am doing it for one automation, input helper is exposed to both google home and alexa

thanks.

I have this

but it’s not showing up in devices at all. was it the button type you use?

Mine is called input_boolean.coming_home

Created it from helpers page as Toggle

The rest of your screenshot is about nabu casa which I don’t use, i am managing that part myself

1 Like

thanks. i created a toggle a few times and expose it - it shows up in devices but i can’t use it as a routine starter tho. its not shown as an option

I’d get the sdk going but that is broken too. such a simple thing

lol just ended up doing it by setting a google home mini to a specific volume between x and y and used that as starter. messy as but it works

this is only temp setup for me until lockly integrates with home assistant.

Ahhh, you want to create a routine in google home, sorry, i am using this helper to trigger an automation on home assistant end.

To do that, you have to put your device into a room in google home. I just tried it now and it is visible as device trigger under the routine

not sure what i’m doing wrong - i have it in a room and it didnt’ show up as an option (the toggle) could be nabu casa diff who knows

Hello all

I think this is the right thread for me toi ask my question, if not I do apologise and is so please be so kind to direct me to the correct thread.

I am new to NR and i just started to learn how to create a flow (i guess)

I’m trying to turn on a light based upon motion, illuminance and time of day

I have a “enent state” (motion detection) that is configured “if State” is On. this node is connected to a “current event state” in which i have set illuminance <= 4

This in turn is connected to Bigtimer inode n which I set a time of 17:00 to 23:45 that is connected to “call service” to turn on the light

This node is connected to a “delay node” which is set to 30 seconds and this in turn is connected to a call service to turn the light off

When I cross in front of the motion sensor, the motion sensor is activate. But

The light does not turn on

If i use the inject node and send a time stamp and connect it to the illuminance node the flow works perfectly.

Therefore i surmise that my motion detection event state is not working

This event state node is configured as follow
Name : Motion
Server: Homeassistant
entity: binary_sensor_entrance _hall_sensor_motion _detection (friendly name: entrance hall motion detection)

However when I deploy the flow after a change the flow work correctly

What did i not configure correctly

Thank you in advance for yous help and teachings

You should always make new threads, if you have a new question.
The old threads might not be exactly about what your issue is and the result is a confusing thread for people searching it up later.
At the same time you will miss many possible answers, because some of the people watching the forum consider old threads already handled.

When you will describe a problem then it is also a good idea to use a screenshot. In Windows you should be able to get one by holding Windows key and Shift down and then press S. The screen get a blackish overlay, which means you can then drag a square around the cut out you want by using the mouse.
The captured screenshot should be able to be posted direct to the forum post by press CTRL+V on Windows.
I am not sure what the options are for Linux and Mac on screenshots, but a google search should solve that or a new post on the forum here.

In some posts you make code will needed posted too and here it as important to post the code and then make sure that there is a blank line above and below the text. Then mark then text and the two blank lines and press the </> icon in the post editors icon bar. This make sure that the formatting is preserved which might be important in the problem solving.

In Node Red we might also benefit from the code, so mark the nodes you have issues with and them that are important to understand the flow to there and then click the three lines in the upper right corner.
Select Export and then Copy to Clipboard.
Insert the text and mark is code as described above.

You might then get an answer with a code text back, which can be copied (upper right corner of the code box will usually reveal a copy icon when holding the mouse over it, which is the easiest way to copy the code) and inserted into Node Red by choosing the three lines again and then Import.
Copy the text in the box and choose import and you get the nodes in the answer in to you Node Red window.

Sometimes you get extra info that can give warnings and now and then also errors when importing flows from others, which is because the flow contains the HA config nodes too.
The is easily fixed by clicking the down arrow below the three lines and choosing Configuration Nodes.
In the list that comes up you will probably find two or more Home Assistant nodes.
The Number to the right of them is the connections to it and your correct one will almost certainly have the highest number, so doubleclick on the others and choose delete.

Lastly you might need to debug in Node Red which is done with the debug node. When using a debug node it is pretty much always a good idea to configure its output to Complete MSG object (I do not understand why this is not the default :)),
The debug node will display messages in the debug window whenever something occur.
The debug window is the bettle icon under the three lines.

Use the debug node with your problem here to see when the motion detector sends a message.
A common issue with motion detects is that they have “cooldown” time before they can be activated again.
Sometimes this cooldown time is high, like 30 secs or more.

When you have read this and played a bit with the debug node in regard to your issue without solving it, then make a new thread and use the hints here to provide information about your flow and what you have tested.

Thank you @WallyR for this lesson and for your quick reply. I will proceed to do what you are suggesting