After modifying its configuration, execute Check Configuration and ensure it passes then execute Reload Manually Configured MQTT Entities (or just restart Home Assistant).
It should, at the very least, report the car charger’s energy value whenever it’s published to the MQTT broker by the car charger. If it fails to do that then I suggest you confirm the MQTT integration is properly installed and configured.
Thank you! I actually had almost your code as I currently have the json_attributes_template commented out. I will now remove the value_template" '{{ value }}'
My mistake was in assuming it would populate with the current values in MQTT but just now discovered that I need to publish something to MQTT and then HA is updated.
The MQTT Sensor simply reports the payload that was published to the topic it’s monitoring.
If whatever device that’s publishing the payload does so as a “retained message” then the MQTT Broker stores the payload. The advantage of this is that whenever Home Assistant is restarted, the moment it re-connects to the MQTT Broker, it receives the stored payload.
If whatever device that’s publishing the payload does not specify it as a “retained message” then the MQTT Broker does not store the payload. Whenever Home Assistant is restarted, the moment it re-connects to the MQTT Broker, it receives no payload (and the corresponding sensor’s value will be unknown). It will only receive a payload when the device publishes it.
Got it! I am the one (or rather HA is) that is publishing to the sensor. I’ve added retain: true to the automation.
Part 2:
I now want this automation that’s triggered by sensor.car_charging_monthly_energy_cost at 23:59 on the last day of the month to also write the value to the corresponding month in the history attributes but that syntax has me baffled at the moment!
alias: Car Charging Monthly Energy Cost - Update
description: ''
trigger:
- platform: state
entity_id:
- sensor.car_charging_monthly_energy_cost
condition: []
action:
- service: mqtt.publish
data:
topic: energy/sensor/car_charger_energy
payload_template: '{{ states("sensor.monthly_energy_cost_car_charger") }}'
retain: true
mode: single