I have a Template Number:
number:
#
#Switch delays
#
- platform: template
id: "Switch1Wait"
name: "Switch 1 Wait"
optimistic: true
min_value: 0
max_value: 600
step: 1
initial_value: 120
restore_value: true
web_server:
sorting_group_id: sorting_group_switch1
sorting_weight: 20
I want to be able to access the value, both to print out in logs, and to use the value in other functions and statements. For logging, I’ve tried:
- logger.log:
format: "DEBUG MAIN PRESS 2: Switch 1 Delay: %i"
args: 'id(Switch1Delay)'
This is part of a Binary Sensor that response to a button press. When I press the button, I see:
(Relevant lines are the 1st and 2nd line in the log.)
The value is currently set at 120, but when I try to log the value of it, I get 0, so I’m not actually getting the value when I try to print it in the log. I would think %i
would be the right pattern to use to print an integer - is something else better? Or is the problem in the next line?
I know if it’s a string, I can access the value, for logging, like this:
- logger.log:
format: " Changed on div by 15 value, TestVar: ->%s<-"
args: id(TestVar).c_str()
But I know c_str() is to read strings terminated with a null byte, so that wouldn’t be appropriate for a number.
Aslo, I’d like to be able to use this value (of the Template Number) in statements, like:
- delay: <template value> seconds
I’ve tried doing some debugging to work this out. I’m not clear if the value of the template is a C++ variable or just a variable within the YAML file that I should be able to read.