My goal is to get a value from a sensor (temperature) and do some math with it and add this new value to a variable.
Afterwards I like to get the value of this variable back in an automation.
I am confused with the use of variables:
how do I have to initialize a variable in automation.yaml? Is this an extra service?
how can I update the variable with a new value?
how can I use this variable in the action of the automation?
Is not part of Home Assistant’s variables. That service call belongs to a custom integration that implements its own style of variables (namely the one created by user snarky-snark).
I don’t know yet how to calculate but the goal is to increase the Red value of RGB if it gets warmer and decrease if it gets colder.
At the same time the blue value should increase if it gets colder.
You will need to determine the temperature range. For example, rgb_color is solid red [255, 0, 0] when the temperature is 25 C or more and solid blue [0, 0, 255] when the temperature is 0 C or less. That represents a range of 25 degrees.
The midway point is approximately 12 degrees and that’s where red and blue are half their max values: [127, 0, 127]. For every 1 degree increase, the red value should increase by 255/25 ~ 10 and the blue value should decrease by the same amount (10).
That’s one possible algorithm for the temperature-based color effect you want.
If I want to start with an input_number do I have to declare them in the configuration.yaml? From this example is the “entity_id” slider1 in this case?
I also found the service: input_number.set_value
Should this be used as an action in the automation to do the calculation?
Sorry, I don’t understand the purpose of an input_number to compute the rgb value.
Is it to serve as a temporary replacement for the temperature sensor so that you can easily experiment with the calculation? If that’s the case then you can define an input_number in configuration.yaml (as per the example you posted) or via the UI using Configuration > Helpers.