Automatic lights are nice but sometimes you would like to disable the automation. This can be achieved nicely by adding an input boolean to Home Assistant that lets you enable/disable the flow from the web UI (from any device).

What you need

  • Node-RED installed (you could re-create this in YAML but I wouldn't recommend that) along with the node-red-contrib-home-assistant-websocket package.
  • Home Assistant
  • Some sort of flow in Node-RED that you don't want to run if disable in HA (such as an automatic light flow for example)

Setup in Home Assistant

Here is an example of an input boolean in the configuration.yaml file for HA:

input_boolean:
  auto_laundry_room_light:
    name: Automatic Laundry Room Light
    initial: on
    icon: mdi:alarm-light

And here is how they look (a sample from my own setup):

Setup in Node-RED

Now all you need to do is add a Current State node that filters out events if the newly added input boolean is disable in HA. Here is an example of this Node:

[{"id":"ea71975.1a67c68","type":"api-current-state","z":"ff717302.0c688","name":"Switch: Auto Laundry Room Light","server":"233a9c63.e2baf4","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.auto_laundry_room_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1280,"y":80,"wires":[[],[]]},{"id":"233a9c63.e2baf4","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

The "If State" option of this node is how you filter out events by sending them to the second output. You will notice I have it set to "is: off" which means if the result is off it will send it to the second output. You could also set it to "is: on" and use the second output if that is easier for you to understand (since you have to think of the logic backwards).

Here is an example of using this switch to toggle an automation for a light on/off:

[{"id":"1eae55a0.def48a","type":"server-state-changed","z":"ff717302.0c688","name":"Motion Laundry Room","server":"233a9c63.e2baf4","entityidfilter":"binary_sensor.motion_laundry_room","entityidfiltertype":"exact","haltifstate":"","outputs":1,"x":400,"y":1740,"wires":[["20e71e7.43434e2"]]},{"id":"20e71e7.43434e2","type":"switch","z":"ff717302.0c688","name":"switch 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":590,"y":1740,"wires":[["2dfe8f66.76b6c","3c4546c7.23a06a"],["2dfe8f66.76b6c"]]},{"id":"6fdd0759.c2af58","type":"api-call-service","z":"ff717302.0c688","name":"Laundry Room Light On","server":"233a9c63.e2baf4","service_domain":"light","service":"turn_on","data":"{ \"entity_id\": \"light.laundry_room_light\" }","mergecontext":"","x":1250,"y":1740,"wires":[[]]},{"id":"f0f19d3a.54c94","type":"api-call-service","z":"ff717302.0c688","name":"Laundry Room Light OFF","server":"233a9c63.e2baf4","service_domain":"light","service":"turn_off","data":"{ \"entity_id\": \"light.laundry_room_light\" }","mergecontext":"","x":1650,"y":1780,"wires":[[]]},{"id":"2dfe8f66.76b6c","type":"trigger","z":"ff717302.0c688","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"60","extend":false,"units":"s","reset":"on","bytopic":"all","name":"","x":930,"y":1780,"wires":[["7a401718.e8fce8"]]},{"id":"cb2dde2c.7a181","type":"server-state-changed","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","entityidfilter":"light.laundry_room_light","entityidfiltertype":"substring","haltifstate":"off","outputs":1,"x":670,"y":1780,"wires":[["2dfe8f66.76b6c"]]},{"id":"d48f05b9.40cc48","type":"api-current-state","z":"ff717302.0c688","name":"light.laundry_room ON","server":"233a9c63.e2baf4","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.laundry_room","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1420,"y":1780,"wires":[["f0f19d3a.54c94"],[]]},{"id":"c8b939ce.0df798","type":"comment","z":"ff717302.0c688","name":"Motion Light that can be disabled in HA","info":"","x":810,"y":1700,"wires":[]},{"id":"3c4546c7.23a06a","type":"api-current-state","z":"ff717302.0c688","name":"Switch: Auto Laundry Room Light","server":"233a9c63.e2baf4","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.auto_laundry_room_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":980,"y":1740,"wires":[["6fdd0759.c2af58"],[]]},{"id":"7a401718.e8fce8","type":"api-current-state","z":"ff717302.0c688","name":"Switch: Auto Laundry Room Light","server":"233a9c63.e2baf4","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.auto_laundry_room_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1160,"y":1780,"wires":[["d48f05b9.40cc48"],[]]},{"id":"233a9c63.e2baf4","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

And there you go! If you have a Hue Dimmer Switch you can make the system even better by intercepting button hold events for the on/off buttons for enabling/disabling your automatic lights (works great for guests that don't have access to HA).  I'll be writing an article about that in the future.