How I Use Home Assistant: Part 4 — Automatically Enable and Disable Sonos Night Mode with Node-RED

Published by Christian Mohn · Read in about 4 min (679 words)

Sonos Beam is my main driver for television audio, which is great, but the sound travels between the floors in my house so I want Night Mode to be enabled late at night. I also do not want to manually have to tweak the night mode settings through the Sonos App, and figured that doing it on a schedule, from within Home Assistant was the way to go.

Info

This series of posts is not intended to be a Node-RED and Home Assistant 101 introduction. There are other resources for that readily available, that does a very good job at explaining how to get up and running:

Workflow description #

  1. At a given time, enable Night Mode on my Sonos
  2. At a given time, disable Night Mode on my Sonos
  3. Profit

In order to get this working, the following Home Assistant integrations and Add-ons needs to be installed and configured:

My final workflow looks like this:

Node-RED Workflow Walkthrough #

1. Bigtimer Node

Like in my Morning Coffee workflow, this one kicks off with a Bigtimer Node.

The On Time item is set to 23:00, and the Off Time is set to 08:00.

  1. Switch Node

The second part of the workflow is a simple switch node, that differentiates between an on or an off event from the Bigtimer Node.

This basically just takes the output from the Bigtimer Node, which is either a value of on or off, and decides the flow from there. The topmost connector on the right hand side is the first value, which in this case is on and the second one is a value of off.

  1. Call Service Nodes

Based on the value from the Switch Node is either on or off, it calls a service in Home Assistant. If the event is on, it proceeds to run Sonos: Enable Night Settings. If the event is off, then it runs the Sonos: Disable Night Settings.

Sonos: Enable Night Setting #

The Call Service Node: Sonos: Enable Night Setting sends a service call to the Sonos integration, with a pre-defined payload. Name is your chosen name, Server is Home Assistant, Domain is Sonos and the Service to call is set_option. In Entity Id the chosen Sonos media player is chosen.

Note

Devices can be grouped in in Home Assistant, and a service call can be sent to a a group if you want this to happen to all your Sonos devices, should you have more than one

For the Data field, the following JSON needs to be put in place:

Data Payload #

This payload sets Sonos Night Sound to on, enables Speech Enhancement and turns off the Status Light on the device.

Although I can clearly hear it when the Sonos changes to Night Mode, being able to quickly see current status by looking for the Status Light is a nice way to verify it

Sonos: Disable Night Settings #

The Call Service Node: Sonos: Enable Night Setting sends a service call to the Sonos integration. This is basically a copy of the Sonos: Enable Night Setting one, with a different name and a different payload in Data. Name is your chosen name, Server is Home Assistant, Domain is Sonos and the Service to call is set_option. In Entity Id the chosen Sonos media player is chosen.

Data Payload #

This payload sets Sonos Night Sound to off, disables Speech Enhancement and turns on the Status Light on the device.

  1. Call Service Node: Notify

In this one, I have also connected another Call Service Node to send a notification to my phone when the workflow runs. Name is your chosen name, Server is yet again Home Assistant, Domain is notify and the Service to call is mobile_app_your_device. No need to put in an Entity Id for this one.

Data Payload #

Emojis and all!

Workflow #

Once all of the nodes are configured, and available in the Node-RED canvas it’s just a matter of connecting them together like this:


This is a post in the Home Assistant 101 series. Posts in this series:


    Post last updated on January 2, 2024: Add author

    About

    vNinja.net is the online hub of Christian Mohn and Stine Elise Larsen.

    The site primarily focuses on IT architecture and data center technologies, with a strong emphasis on virtualization and related topics.
    While the main content revolves around these areas, you'll also find a range of other subjects covered from time to time, reflecting the interests of authors.

    Sponsors