Im looking to compare the last value of a sensor to the new value -
I have a sensor which just collects a ever-increasing sequence number,
the sensor is checking lorawan frame numbers are sequential to detect lost frames; 1,2,3,5… = we lost frame 4).
I have tried the automation; with a condition:
{{ (trigger.to_state.state|int - trigger.from_state.state|int) > 1 }}
But this only triggers if we loose one (or more frames), I need a better way to count lost frames as we are losing a few in a row at some times.
Can anyone suggest how I can actually get the value of trigger.from_state so I can then do a basic math template to find the difference between the successive values?
sensor value = (trigger.to_state.state|int - trigger.from_state.state|int)
or can I parse this value out in my automation in an MQTT payload (for example)?
# get the previous value of a sensor example from:
# https://www.home-assistant.io/docs/automation/templating/
template:
- trigger:
- platform: state
entity_id:
- sensor.waterit0005_ttn_meta_framecount
sensor:
- name: waterit0005_ttn_meta_framecount_last
state: '{{ trigger.from_state.state }}'