Busta999x
(Michael Horton)
June 19, 2025, 4:07pm
1
Copied most of this from a site to get the Pixel Display to show house battery data on its screen.
Getting
Message malformed: extra keys not allowed @ data [“state”]
I can’t find a line with [“state”] and cannot see where any extra data is entered around anything with the word state in it.
Can any experienced person help me identify and resolve this error please?
id: awtrix_app_home_battery
alias: Awtrix Home Battery Charge
description: Publishes the current home battery charge to the Awtrix clock
trigger:
- alias: Matrix turned on
platform: state
entity_id: light.awtrix_55fe48_matrix
state: "on"
- alias: Charge level/mode changes
platform: state
entity_id:
- sensor.victron_battery_soc
- sensor.victron_system_battery_state
condition: []
action:
- service: mqtt.publish
data:
payload: >-
{%- set charge = states('sensor.victron_battery_soc') |
float(-1) | round(0) %}
{%- set mode = states('sensor.victron_system_battery_state')
%} {%- if mode == "Charge" %}
{%- if charge > 85 %}
{%- set icon = 32047 %}
{%- elif charge > 69 %}
{%- set icon = 32049 %}
{%- elif charge > 51 %}
{%- set icon = 32050 %}
{%- elif charge > 34 %}
{%- set icon = 32051 %}
{%- elif charge > 17 %}
{%- set icon = 32052 %}
{%- else %}
{%- set icon = 32053 %}
{% endif %}
{%- elif mode == "Discharge" %}
{%- if charge > 85 %}
{%- set icon = 32059 %}
{%- elif charge > 69 %}
{%- set icon = 32058 %}
{%- elif charge > 51 %}
{%- set icon = 32057 %}
{%- elif charge > 34 %}
{%- set icon = 32056 %}
{%- elif charge > 17 %}
{%- set icon = 32055 %}
{%- else %}
{%- set icon = 32054 %}
{% endif %}
{%- else %}
{%- if charge > 90 %}
{%- set icon = 13735 %}
{%- elif charge > 70 %}
{%- set icon = 13732 %}
{%- elif charge > 40 %}
{%- set icon = 13731 %}
{%- elif charge > 10 %}
{%- set icon = 13725 %}
{%- else %}
{%- set icon = 13734 %}
{% endif %}
{%- endif %} {# Output #} { "text": "{{ charge }} %", "icon": "{{
icon }}", "progress": {{ charge }} }
topic: awtrix_xxxxxx/custom/batterycharge
qos: 0
retain: false
WallyR
(Wally)
June 19, 2025, 4:17pm
2
Your state trigger is wrong.
Busta999x
(Michael Horton)
June 22, 2025, 3:19pm
3
This is the original posted Automation is this also wrong?
automation:
- id: awtrix_app_home_battery
alias: Awtrix Home Battery Charge
description: Publishes the current home battery charge to the Awtrix clock
trigger:
- alias: Matrix turned on
platform: state
entity_id: light.awtrix_xxxxxx_matrix
state: on
- alias: Charge level/mode changes
platform: state
entity_id:
- sensor.battery_state_of_charge
- sensor.battery_mode
condition: []
action:
- service: mqtt.publish
data:
payload: >-
{%- set charge = states('sensor.battery_state_of_charge') | float(-1) | round(0) %}
{%- set mode = states('sensor.battery_mode') %}
{%- if mode == "Charge" %}
{%- if charge > 85 %}
{%- set icon = 32047 %}
{%- elif charge > 69 %}
{%- set icon = 32049 %}
{%- elif charge > 51 %}
{%- set icon = 32050 %}
{%- elif charge > 34 %}
{%- set icon = 32051 %}
{%- elif charge > 17 %}
{%- set icon = 32052 %}
{%- else %}
{%- set icon = 32053 %}
{% endif %}
{%- elif mode == "Discharge" %}
{%- if charge > 85 %}
{%- set icon = 32059 %}
{%- elif charge > 69 %}
{%- set icon = 32058 %}
{%- elif charge > 51 %}
{%- set icon = 32057 %}
{%- elif charge > 34 %}
{%- set icon = 32056 %}
{%- elif charge > 17 %}
{%- set icon = 32055 %}
{%- else %}
{%- set icon = 32054 %}
{% endif %}
{%- else %}
{%- if charge > 90 %}
{%- set icon = 13735 %}
{%- elif charge > 70 %}
{%- set icon = 13732 %}
{%- elif charge > 40 %}
{%- set icon = 13731 %}
{%- elif charge > 10 %}
{%- set icon = 13725 %}
{%- else %}
{%- set icon = 13734 %}
{% endif %}
{%- endif %}
{# Output #}
{ "text": "{{ charge }} %", "icon": "{{ icon }}", "progress": {{ charge }} }
topic: awtrix_xxxxxx/custom/batterycharge
qos: 0
retain: false
Yes, the configuration variable state
is invalid for a trigger. A State trigger can use the configuration variables to
or from
if you want to trigger only on specific state changes.
The original has a second error on the same line in that the word "on"
always needs quotation marks so it’s not converted to a boolean value… that seems to have been corrected in your automation.
Busta999x
(Michael Horton)
June 22, 2025, 4:14pm
5
OK out of my depth here need to reset and get into yaml another day.
I copy pasted it - I changed the target device/Battery SOC and Battery state.
I was hoping it would be quite straightforward.
I got the automation from [AWTRIX 3 ] (AWTRIX 3 )
I’ll look for another way of doing it.
Thanks for your assistance, much appreciated - I’ll use a notification to drive it periodically until I can allocate a lot more time to get into YAML .
It is… all you need to do is change state: "on"
to to: "on"
1 Like
123
(Taras)
June 22, 2025, 6:56pm
7
AWTRIX 3 has misled you; the example contains invalid syntax (State Trigger doesn’t have a state
option). Its author has made a mistake.
I doubt another way is as simple as correcting the mistake (replace the word state:
with to:
).
1 Like
Busta999x
(Michael Horton)
June 23, 2025, 2:31pm
8
Many thanks for this
I was still getting the error message until I changed state: to to:
Busta999x
(Michael Horton)
June 23, 2025, 2:34pm
9
And here is where subject matter expertise comes in
I would have never have picked up the word “state” needs to change to “to” many thanks and it looks like it is running now
Simple if you know how
I am getting up to speed with Home Assistant, YAML, and Node Red at the same time.
Having fun with it so trying out pre canned YAML so I can see you it works and get a better understanding of it.
Thank you all for your help!
1 Like