Currently my favorite automation is the one that dims my living room lights when my Chromecast is detected playing something. It will also bring the lights back to their normal setting whenever content is stopped/paused. It always surprises my Friends/Family when they see it in action.

Requirements

In order to accomplish this you will need Node-RED and Home Assistant installed and configured to work together (via the package node-red-contrib-home-assistant-websocket in Node-RED). You will also need a bulb of some sort (I am using Hue bulbs) and a Chromecast setup in HA.

Setting it up

For this setup I created a Input Number slider in HA that lets you set how dim to make the lights. If you move the slider and the Chromecast is currently playing it will update in real time (instead of having to pause/play to apply the new brightness). Here is what you need to add to your HA configuration.yaml file for this slider:

input_number:
  living_room_chromecast_dim_amount:
    name: Living Room Chromecast Dim Amount
    icon: 'mdi:lightbulb-on'
    unit_of_measurement: "%"
    min: 0
    max: 255
    step: 1

We will also need to add a Input Boolean that lets us turn on/off this automation. Just as before add this to your HA config:

input_boolean:
  living_room_chromecast_dim_lights:
    name: Living Room Chromecast Dim Lights
    initial: on
    icon: mdi:alarm-light

You will then need to edit your groups.yaml file to get your new slider and switch to load in on the Home Assistant UI (here for more information). Here is an example of what I have setup for this:

automation_switches:
  name: Automations
  control: hidden
  entities:
    - input_boolean.living_room_chromecast_dim_lights
    - input_number.living_room_chromecast_dim_amount

After restarting Home Assistant this is what it should look like in the UI:

Now we got to setup the actual automation. We will be doing this inside of Node-RED (click here if you need more information on why I prefer Node-RED over HA's YAML). Here is the flow I have been using:

[{"id":"50ab4175.b134a","type":"server-state-changed","z":"ff717302.0c688","name":"Living Room Chromecast","server":"233a9c63.e2baf4","version":"1","entityidfilter":"media_player.living_room","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":210,"y":2440,"wires":[["dc13e69f.935ce8"]]},{"id":"ff2d5f8f.775f4","type":"api-call-service","z":"ff717302.0c688","name":"Living Room Lamp ON","server":"233a9c63.e2baf4","service_domain":"light","service":"turn_on","data":"{ \"entity_id\": \"light.living_room\" }","mergecontext":"newMsg","x":2020,"y":2440,"wires":[[]]},{"id":"caea3a8d.73ea28","type":"function","z":"ff717302.0c688","name":"Brightness Payload Formatter","func":"var newMsg =  {\n    payload: {\"data\":{\"brightness\":parseInt(msg.payload)}}\n};\nreturn newMsg;","outputs":1,"noerr":0,"x":1730,"y":2420,"wires":[["ff2d5f8f.775f4"]]},{"id":"c71bfb56.2bf448","type":"function","z":"ff717302.0c688","name":"Brightness Payload Formatter (100%)","func":"var newMsg =  {\n    payload: {\"data\":{\"brightness\":254}}\n};\nreturn newMsg;","outputs":1,"noerr":0,"x":1750,"y":2460,"wires":[["ff2d5f8f.775f4"]]},{"id":"b14799ed.79be08","type":"comment","z":"ff717302.0c688","name":"Change living room brightness depending if chromecast is playing or not","info":"","x":1030,"y":2360,"wires":[]},{"id":"dc13e69f.935ce8","type":"function","z":"ff717302.0c688","name":"Check if payload changed","func":"// without this code it would spam the other HA nodes and cause HA to lock up\nvar last_value = flow.get('last_living_room_light_value')||null;\nif(\n    typeof msg !== 'undefined' && \n    typeof msg.payload !== 'undefined' && \n    msg.payload !== last_value\n) {\n    flow.set('last_living_room_light_value', msg.payload);\n    return msg;\n}\n","outputs":1,"noerr":0,"x":450,"y":2440,"wires":[["978bef8.3a33d1"]]},{"id":"fa18d3ac.e8d84","type":"switch","z":"ff717302.0c688","name":"","property":"last_living_room_light_value","propertyType":"flow","rules":[{"t":"eq","v":"playing","vt":"str"},{"t":"neq","v":"playing","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":1170,"y":2440,"wires":[["bf010792.506818"],["c71bfb56.2bf448"]]},{"id":"978bef8.3a33d1","type":"api-current-state","z":"ff717302.0c688","name":"Chromecast Dim Lights Switch On","server":"233a9c63.e2baf4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.living_room_chromecast_dim_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":720,"y":2440,"wires":[["c1a989da.9661e8"],[]]},{"id":"c1a989da.9661e8","type":"api-current-state","z":"ff717302.0c688","name":"Is Living Room Light On","server":"233a9c63.e2baf4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.living_room","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":990,"y":2440,"wires":[["fa18d3ac.e8d84"],[]]},{"id":"2b9bc42d.c2302c","type":"server-state-changed","z":"ff717302.0c688","name":"living_room_chromecast_dim_amount","server":"233a9c63.e2baf4","version":"1","entityidfilter":"input_number.living_room_chromecast_dim_amount","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":170,"y":2400,"wires":[["743127de.78fc08"]]},{"id":"bf010792.506818","type":"api-current-state","z":"ff717302.0c688","name":"living_room_chromecast_dim_amount","server":"233a9c63.e2baf4","version":"1","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_number.living_room_chromecast_dim_amount","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1430,"y":2420,"wires":[["caea3a8d.73ea28"]]},{"id":"743127de.78fc08","type":"trigger","z":"ff717302.0c688","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"2","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":400,"y":2400,"wires":[["978bef8.3a33d1"]]},{"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}]

After you get that imported and setup in Node-RED you should be able to cast something to your Chromecast and see the lights dim to your selected amount! Once you pause/stop/turn off the Chromecast the lights should go back to full brightness.

Conclusion

Since implementing this automation my wife and me love it. I love seeing automations respond to what you are doing and this is my favorite flow so far for showing this. It's also pretty surprising at how fast everything responds (turning off the TV for example powers down the Chromecast and the lights respond immediately instead of taking a couple seconds). I was really stoked to write about this after using it for a couple months.

Going further

There is one thing to consider though. Since I use motion lights in my Living Room I had to go a step further and edit my living room automation to check if Chromecast is currently playing or not before turning on the light. This way the dimming still happens if the lights were off when Chromecast started playing but got turned on later due to motion. This was easy to setup but if you want to do the same just leave a comment below and I can go into this further.

I also setup a Hue remote so that if the Off button is held for a couple seconds it disables automatic lights in my living room and will re-enable the automation if the On button is held. I will be writing an article about how to accomplish this in the future. This has been really handy for guests that do not have access to my Home Assistant UI.

And lastly if you want to customize the color of your bulbs when content is playing you could easily modify my flow above to do just that. I have circadian lighting setup so I prefer to just dim my lights but you have the power to do whatever you want.

Feedback

If you found this article helpful please leave a comment below (it really helps inspire me to write more). I also would love to hear back if you ended up changing my flow or have any suggestions.