Sorry if it’s a newbie question, none of this is my native language and I’ve been been googeling all day without luck.
How can I set a variable and use it for output as an attribute? For some reason, currentPrice won’t keep its value past the first print in this example:
Unlike OP, you are creating a trigger-based Template sensor. That difference allows you to set widely available variables at multiple places… but I don’t see anywhere that would make a big difference in your example configuration.
I have 80 push buttons in an old LK IHC low voltage lighting control system that I have connected to Home Assistant via an esp32
I would like to be able to distinguish between long and short presses
I would like to define in an easy way what should happen when a button is pressed.
As you can see in my code it returns an attr with 2 values, I need more, I would like to have these values returned in each attr.
I know I can set up 160 lines for each attribute, but I don’t think that’s smart. And it will be difficult to maintain.
my idea is that folders & map can be stored in a variable, which i could then use to define the contents of attributes.
but i can’t figure out the correct syntax
I am not sure if the following information will help with your project but a Trigger-based Template Sensor can have a variables section.
Any variables you define in that section can be referenced in the Sensor’s state and its attributes.
Example
The following (contrived) example defines four variables in the variables section. The variables are then referenced in state and in the color, and level attributes.