I have working sensor, it gives value as expected
- name: "e-Up!_battery_soc"
unique_id: "eup_battery_soc"
state_topic: "wican/e-up/can/rx"
state_class: "measurement"
value_template: >-
{% if value_json.frame[0].id == 2029 %}
{% set PID = value_json.frame[0].data[3] %}
{% if PID == 140 %}
{% set AA = value_json.frame[0].data[4] %}
{{ ((AA - 24)/2.15) | round(0) | int }}
{% endif %}
{% endif %}
But if i try to set it up as helper like this
{% set value_json = states('sensor.e_up_raw_data') %}
{% if value_json.frame[0].id == 2029 %}
{% set PID = value_json.frame[0].data[3] %}
{% if PID == 140 %}
{% set AA = value_json.frame[0].data[4] %}
{{ ((AA - 24)/2.15) | round(0) | int }}
{% endif %}
{% endif %}
It doesnt work, if i put it in template editor
it gives me error UndefinedError: 'str object' has no attribute 'frame'
My raw_data
sensor gives exactly same data as mqtt topic, setup like this
- name: "e-Up!_raw_data"
unique_id: "eup_raw_data"
state_topic: "wican/e-up/can/rx"
value_template: "{{ value }}"
I would like to get it working atleast in template editor
, easier to test different calculations etc
Is it possible to get it working, do i have something wrong in my setup.
MQTT message is:
{
"bus": "0",
"type": "rx",
"ts": 7119,
"frame": [
{
"id": 2029,
"dlc": 8,
"rtr": false,
"extd": false,
"data": [
4,
98,
2,
140,
128,
170,
170,
170
]
}
]
}