Hopefully someone can point out what I’m doing wrong in the following automation
I have a file sensor which is updated by a shell script
this file sensor needs split into two seperate variables with an ! as the field delimiter
In the data template testing editor I have go what I think is the correct format see picture below
the automation is as follows
- id: '1682845133159'
alias: GetPrinterInfo
#
# sensor.testpagecountfile is a file sensor
# and is formatted as XXX!YYY
#
# where XXX is the current pagecount
# YYY is the total pagecount
#
description: ''
trigger:
- platform: event
event_type: ''
- type: connected
platform: device
device_id: 40e2585b071d9cbc2439dbe1d94a755e
entity_id: binary_sensor.samsung_sl_m3820nd
domain: binary_sensor
condition: []
action:
- service: shell_command.get_page_count
data: {}
- service: counter.configure
data:
minimum: 0
maximum: 100
value: '{{ states(''sensor.samsung_sl_m3820nd_toner_black'') }}'
target:
entity_id: counter.tonerlevel
- service: counter.configure
data:
value_template: set pages = states('sensor.testpagecountfile').split("!")
minimum: 0
maximum: 100000
value: "{{ pages[0] }}"
target:
entity_id: counter.pagecount
- service: counter.configure
data:
value_template: set pages = states('sensor.testpagecountfile').split("!")
minimum: 0
maximum: 100000
value: "{{ pages[1] }}"
target:
entity_id: counter.totalpagecount
mode: single
but the pages variable is reported as undefined
Logger: homeassistant.components.automation.getprinterinfo
Source: components/automation/__init__.py:254
Integration: Automation (documentation, issues)
First occurred: 01:29:11 (1 occurrences)
Last logged: 01:29:11
Error while executing automation automation.getprinterinfo: Error rendering data template: UndefinedError: 'pages' is undefined
I have tried various positions and formats for the value_template lines but with out success
I clearly dont understand how templates and variables are used in automations and several hours of reading and editing have not made any difference !!
I can easily split the variable using two differnt file sensors the following works perfectly
- platform: file
name: pagecountfile
file_path: /config/PageCount.txt
value_template: '{{ value.split("!")[0] }}'
- platform: file
name: totalpagecountfile
file_path: /config/PageCount.txt
value_template: '{{ value.split("!")[1] }}'
but I just assumed I would be able to do it within the automation
If any one could explain to me what I’m doing wrong I would be very gratetfull