Liese
(Jörg)
April 29, 2020, 5:40am
1
Hi, I tried to get it working.
Like here
For me, the state trigger was triggering every time I restarted Home Assistant.
I’ve built off this to try a different approach.
First install the “Variable” integration in HACS
Then:
configuration.yaml
var:
printer_pages_at_month_start:
friendly_name: 'HP Printer Pages at month start'
initial_value: 50
sensor:
- platform: template
sensors:
pages_left:
value_template: "{{ states('var.printer_pages_at_month_start')|int - states('sensor.hp_printer_printer')|int …
I think in exactly the same way. OK, I deleted the Trigger etc. for debugging…
VAR component is installed…via HACS.
I included following in the config.yaml file:
var:
printer_pages_at_month_start:
friendly_name: 'HP Printer Pages at month start'
initial_value: 50
I added following automation - initially without var.update -
to automation.yaml
- id: hp_instant_ink_per_month
alias: HP Instant Ink per Month
trigger: []
condition: []
action:
- service: var.set
data:
entity_id: var.printer_pages_at_month_start
value: "{{ states('sensor.hp_printer_printer')|int }}"
- service: var.update
data:
entity_id: var.printer_pages_at_month_start
But the variable won’t be updated.
Any idea what’s wrong here?
It seems I am struggling again with yaml ?
Best regards
Joerg
Liese
(Jörg)
April 29, 2020, 8:27am
3
Thanks for the link.
I am confused about the Automation GUI and the automation.yaml file.
I changed to data_template in the automation.yaml.
Then I Reloaded atomations , entered the automation GUI and deleted the Trigger/Condition.
But - using data_template - the Service data field in the GUI is empty,
while the automation.yaml shows this
- id: hp_instant_ink_per_month
alias: HP Instant Ink per Month
trigger: []
condition: []
action:
- data_template:
value: '{{ states(''sensor.hp_printer_printer'')|int }}'
entity_id: var.printer_pages_at_month_start
service: var.set
And still - after Reload Automations/ Reload Dashboard (holding Shift to delete Cache) - that is not updating the variable.
Regards,
Jörg
Tinkerer
(aka DubhAd on GitHub)
April 29, 2020, 11:57am
4
The automation editor doesn’t cope with templates in actions, unfortunately.
Of course, the automation has no trigger, so it’ll never run. Presumably you’ll be adding that? Or maybe you should use a script instead, since it doesn’t require a trigger.
Liese
(Jörg)
April 29, 2020, 12:07pm
5
OK, but if I use EXECUTE (as manual trigger in the GUI) - just for testing - that should bridge the trigger.
That way I can check CONDITION and ACTION.
That’s why Trigger & Condition is empty.
Just to test the Action.
But nothing happens…so I am still wrióng?
Liese
(Jörg)
April 30, 2020, 9:17am
7
Shame on me
- id: hp_instant_ink_per_month
alias: HP Instant Ink per Month
trigger:
- platform: time
at: 06:00:00
condition:
- condition: template
value_template: '{{ now().day == 12 }}'
action:
- data_template:
value_template: '{{ states(''sensor.hp_6970_printer'')|int }}'
entity_id: var.printer_pages_at_month_start
service: var.set
This worked (but only via Notepad…) as you said.
The entity name I forgot to change to hp_6970…
Thx for your hints!
Jörg
1 Like
techy
(daljit sandhu)
March 9, 2021, 7:09pm
8
i am having issues too get this to work. my page count is showing to 346, i want to reset it to custom value.
@techy , do your logs show anything relevant?
techy
(daljit sandhu)
April 1, 2021, 4:55pm
10
you mean supervisor logs ? sorry i am not too familiar with setting up templates.