Christmas tree coloring depending on stocks

This will most likely be the most unnecessary automation so far. The background is that I bought some stocks for my kids. I wanted them to see if it was going up or down. If you follow this guide your tree will be green if stock market is up or red if it is down.

I have used the following to make this work:

  • Twinkly Christmas tree led light
  • Node Red
  • Home Assistant with HACS
  • A Christmas tree

I assume you already have a working Home Assistant and that you have connected your Twinkly to your wifi.If yes continue.

The first thing we will do is to add the Avanza integration to HA. It can be found in hacs. After add your stocks under sensors.

 - platform: avanza_stock stock: - id: 551053 name : Solaredge shares: 4 purchase_price: 292 - id: 678757 name: ExpreS2ion <pre>

You should now have two new entities. The problem is that most information is stored in states. See below. We want to be able to use more information like change. In order to get this we will create some sensors.

Now add two templates. The only thing they will do is to create a sensor of the change in SEK or dollars. So if your shares is +5$ one day this sensor will show this. Uou can create more sensor if you need them. For example a created a sensor showing how much money we have made so far. This is displayed on my Magic Mirror.

friendly_name: 'Solaredge-upordown'
value_template: '{{ states.sensor.solaredge.attributes["change"] }}'
unit_of_measurement: '$'

friendly_name: 'ExpreS2ion-upordown'
value_template: '{{ states.sensor.ExpreS2ion.attributes["change"] }}'
unit_of_measurement: 'SEK'


Now make sure you can see the sensors. I added them to a card to see that it works.









Now head over to Node Red. I have used Node Red as the Home Assistant integration for Twinkly is only able to turn on or off or change the brightness of the lights.

Start by adding the Twinkly node to Node Red.

The first node is the events state node from Home Assistant. Use the sensor.solaredgeupordown here. The second node is a switch. I have just used <0 and >0 here to see if it is going up or sown.

Then we have two changes nodes. In the color field I have used

{ "mode": "loop", "delay": 50, "steps": 15, "colors": [ [ 0, 200, 0, 0 ], [ 0, 100, 0, 0 ] ] }

This will set the lights to green. You can change this to something else if you want to. Make sure to read the Twinkly node documentation. You can use static, loop or blink.

This is about everything. If you want to make it more complicated you can.

  • Add all your stocks to one sensor and use this value as a marker of your stock portfolio.
  • Make it blink if a certain value is reached
  • Set it to normal colors when the stockmarket is closed

Final result