How do I create toggle switch in UI and read it in node red

I have PIR in my garage and when I go inside and leave roller door open I want to be able to flick on a toggle switch on lovelace so that if the PIR detects movement in the garage it plays an announcement on my google home unit inside.

I done about an hour of searching and am pretty sure I’ve got a handle on what I need to do with the exception of the toggle switch in lovelace and how to create a toggle switch that is not linked to an entity that node red could read.

I probably over complicate it by creating a dummy mqqt switch. If you don’t set a state topic it toggles the switch - I am sure there is an easier way though

1 Like

Would an input_boolean fit the bill? The state can certainly be read by node red.

1 Like

I have read about creating this type of thing in a template which looks like it would probably do it.

A boolean is probably the most common thing I have seen come up in post around, possibly this might be the way to do it, I need to do some further searching as people just say use a boolean but I have no what/how to use it.

Just create a new input_boolean in configuration.yaml

input_boolean:
°°armed:
°°°°name: the alarm is armed
°°°°initial: off

(replace ° with spaces)

Then use a current state node (as you did in your screenshot) and use

input_boolean.armed

as entity ID.

Don’t know why you would need the switch node (the yellow one in your screenshot) for this.

1 Like

Cool getting some great info. I got some time today (wives gone out) to make some work of this.

I just quickly made up dummy flow of what I guessed to make it easier for people to get visual and comment.

1 Like

Ok so I had less time today than I hoped and whilst this isn’t the finished product thanks to posts so far I have been able to work out different ways of going about this I have implemented @capstan1 suggestion successfully into a circuit from a toggle switch on the dashboard which I can enable and disable the circuit.

I have used my garage lights as tester and not setup the google cast output yet which will be the next thing I do.

Here is pics from each area:
garage1
I added my code to the configuration.yaml file and rebooted system (here is official notes on boolean).


Dashboard toggle (I used multiple entities as trial so I would get the toggle switch)


I created basic circuit


This is what the state settings look like with the boolean entity.


For voice output tts to google homes. One TTS for each speaker.

[{"id":"2ef4a7e5.ad2da8","type":"api-current-state","z":"71a035ed.6855dc","name":"Arm switch on?","server":"31325ed1.2c0d02","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.armed","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":380,"y":100,"wires":[["dba2e90a.110658","b59ebbd9.767e78","f35dad88.df9c6"],[]]},{"id":"dba2e90a.110658","type":"api-call-service","z":"71a035ed.6855dc","name":"TTS - living room","server":"31325ed1.2c0d02","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.googlehome8590\",\"message\":\"Motion Detected in the Garage.\"}","mergecontext":"","output_location":"data","output_location_type":"msg","x":710,"y":98,"wires":[[]]},{"id":"82aa70f0.75dec","type":"trigger-state","z":"71a035ed.6855dc","name":"Garage","server":"31325ed1.2c0d02","entityid":"binary_sensor.motion_sensor_158d000209138f","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"zucts57zuxe","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":100,"y":100,"wires":[["2ef4a7e5.ad2da8"],[]]},{"id":"b59ebbd9.767e78","type":"api-call-service","z":"71a035ed.6855dc","name":"TTS - bathroom","server":"31325ed1.2c0d02","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.googlehome8111\",\"message\":\"Motion Detected in the Garage.\"}","mergecontext":"","output_location":"data","output_location_type":"msg","x":700,"y":151,"wires":[[]]},{"id":"f35dad88.df9c6","type":"api-call-service","z":"71a035ed.6855dc","name":"TTS - garage","server":"31325ed1.2c0d02","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.googlehome0059\",\"message\":\"I detect I am not alone, help, help, I am notifying the owner.\"}","mergecontext":"","output_location":"data","output_location_type":"msg","x":690,"y":202,"wires":[[]]},{"id":"47163004.62f3e","type":"comment","z":"71a035ed.6855dc","name":"Garage Detection","info":"","x":107,"y":55,"wires":[]},{"id":"31325ed1.2c0d02","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]
1 Like