Can't get set.var to run ? yaml problem?

Hi, I tried to get it working.
Like here

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

Rule #1 of templating:

  1. You must use data_template in place of data when using templates in the data section of a service call.

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

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.

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?

Check your log file

Shame on me :slight_smile:

- 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

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?

you mean supervisor logs ? sorry i am not too familiar with setting up templates.