node-red-contrib-home-assistant-websocketnode-red-contrib-home-assistant-websocket
Guides
Nodes
FAQ
Cookbook
Scrubber
Discussions
Discord
Github
Guides
Nodes
FAQ
Cookbook
Scrubber
Discussions
Discord
Github
  • Guides

    • Getting Started
    • First Automation
    • Action Node Tips and Tricks
    • Conditionals
    • Mustache Templates
    • JSONata

      • JSONata
      • JSONata primer
    • Diagnostics Information
  • Custom Integration

    • Getting Started
    • Exposed Nodes
  • Contribute to

    • Development
    • Documentation

First Automation

For your first automation, let's keep it simple by setting up a light to turn on when the sun sets and off when it rises.

This example uses the sun.sun entity in Home Assistant, which has states below_horizon and above_horizon, to trigger the light.

Events: State Node

  1. Drag an Events: state node onto the workspace and double-click it to edit.

screenshot

Entity ID Configuration

  1. In the Entity ID field, enter sun.sun. This is the entity that will trigger the automation.

If State Condition

  1. The If State condition checks the entity's state when the node is triggered. If the condition is true, the message will be sent through the top output; if false, it will be sent through the bottom output. If no condition is set, all messages will pass through a single output.

    For this example, set the If State to above_horizon.

screenshot

Action Node

  1. Now, let's set up the actions that will be triggered. Most Home Assistant interactions are done through action calls, which we'll handle with the Action node.

  2. Drag two Action nodes onto the workspace and connect them to the outputs of the Events: state node.

screenshot

  • Since we set the If State to above_horizon, the top output will turn off the light, and the bottom output will turn it on.
  1. Configure the Action nodes:
    • Action: light.turn_off (for the top output) and light.turn_on (for the bottom output)
    • Entity: light.front_porch

screenshot

Complete Automation

  1. Once you've configured everything, deploy your flow. You now have your first working automation in Node-RED!

screenshot

[{"id":"b74ada49.d7e408","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"above_horizon","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":244,"y":784,"wires":[["1f467cbb.0c3983"],["da5ff3e0.cbb2a"]]},{"id":"1f467cbb.0c3983","type":"api-call-service","z":"ffbd7f06.4a014","name":"","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.front_porch","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":474,"y":784,"wires":[[]]},{"id":"da5ff3e0.cbb2a","type":"api-call-service","z":"ffbd7f06.4a014","name":"","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front_porch","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":474,"y":832,"wires":[[]]}]

Related Resources:

  • Importing and Exporting Flows
  • Action Node Documentation
  • Events: State Node Documentation
  • Conditionals in Node-RED
Help us improve this page!
Last Updated:
Contributors: Jason, jason
Prev
Getting Started
Next
Action Node Tips and Tricks