I have the following esphome to send a time stamp when the voltage update happens.
# Voltage Sensor
sensor:
- platform: adc
pin: GPIO1
accuracy_decimals: 4
name: "Battery voltage"
attenuation: auto
update_interval: 10s
on_value:
- mqtt.publish:
topic: tractor-battery/voltage_timestamp
payload: !lambda |-
return to_string(id(sntp_time).now().timestamp);
# SNTP
time:
- platform: sntp
id: sntp_time
timezone: "xxx"
servers: "192.168.1.1"
update_interval: 10s
Note: 10s is purely for testing and will be reduced once in production, and this works fine and I get this in mqtt explorer:
So now I want to consume the MQTT timestamp in home assistant and I think the right way to do that is via an mqtt sensor to read the value. So I have split out mqtt.yaml from the configuration.yaml and this seems fine (new to me though).
In that file I have the following:
-sensor
- name: battery_volts_timestamp
unique_id: e3ff039b-4c77-4bc0-8dac-66de50129002
device_class: timestamp
state_topic: battery/voltage_timestamp
value_template: "{{ as_timestamp(value) | timestamp_local }}"
and nothing is appearing in the state for this entity.
What I am doing wrong? I am guessing its around the way the payload is referenced in the template, but not clear and this is the question I am focussed on.