ashscott
(Ash)
1
The title says it all, hopefully.
Here’s what I’ve tried, which doesn’t pass config check.
water_change_counter_dec:
name: 'Water change decrement litres'
restore: 'true'
initial: { states('input_number.water_change_amount')}
step: 1
icon: mdi:counter
It seems that input_number is of kind ‘float’ and counter requires ‘integer’.
Is there a way to achieve this?
eggman
(bertie basset)
2
Doesn’t look like templates are supported there.
Maybe an automation when input_number.water_change_amount changes to run the counter.configure service?
Service counter.configure
With this service the properties of the counter can be changed while running.
Service data attribute |
Optional |
Description |
entity_id |
no |
Name of the entity to take action, e.g., counter.my_custom_counter . |
minimum |
yes |
Set new value for minimum. None disables minimum. |
maximum |
yes |
Set new value for maximum. None disables maximum. |
step |
yes |
Set new value for step. |
initial |
yes |
Set new value for initial. |
value |
yes |
Set the counters state to the given value. |
123
(Taras)
3
The template you’ve created is invalid. It’s missing braces and quotes:
initial: { states('input_number.water_change_amount')}
A valid template would look like this:
initial: "{{ states('input_number.water_change_amount') }}"
HOWEVER, I may be wrong but I don’t believe the initial
option accepts a template.
In that case, an alternative is to set the counter’s initial
option at startup, using an automation like this:
- alias: 'Initialize Counter'
trigger:
platform: homeassistant
event: start
action:
service: counter.configure
data_template:
entity_id: counter.water_change_counter_dec
initial: "{{ states('input_number.water_change_amount') }}"
ashscott
(Ash)
4
You are correct there. I’ll need to convert the float first:
{{ states(‘input_number.water_change_amount’) | int }}
That’s something to get me started.
How do I detect a change in input_number so that I can have the change occur any time rather than just at start?
Thank you for the help all.
123
(Taras)
5
Like this:
- alias: 'Initialize Counter'
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.water_change_amount
action:
service: counter.configure
data_template:
entity_id: counter.water_change_counter_dec
initial: "{{ states('input_number.water_change_amount') | int }}"
EDIT
Correction. Fixed entity_id
in 2nd trigger.
ashscott
(Ash)
6
Thank you! I appreciate your time.
That works great.
Just for completeness, the solution should be:
- alias: 'Set water change counter initial to water change amount'
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.water_change_amount
action:
service: counter.configure
data_template:
entity_id: counter.water_change_counter_dec
initial: "{{ states('input_number.water_change_amount') | int }}"
1 Like