MQTT sensors 2021.12.8 timestamp and other changes

So one of the recent core updates (2021.12.8) has rendered these MQTT devices unusable for me. Can someone shed some light of the error message??

I’ve tried adding an availability topic, although this device doesn’t post an online, offline message.
I sort of played around with the timesstamp, timestamp_local. they seem to be the most frustrating.

I had a look through this link from petro, although it doesn’t seem to relate to MQTT sensors.

Any tips would be welcomed.

Logger: homeassistant.helpers.template
Source: helpers/template.py:1791
First occurred: 16:54:29 (532 occurrences)
Last logged: 17:35:12

Template variable error: 'value_json' is undefined when rendering '{{ value_json.IDC1 }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.IDC2 }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.PDC1 }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.PDC2 }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.status }}'

Template variable error: 'value_json' is undefined when rendering '{{ value_json.Timestamp_local }}'

MQTT message json

(Timestamp: "09/01/2022 17:25:03",SunRise: "09/01/2022 06:10:00",SunSet: "09/01/2022 20:43:00",InvSerial: 2100443252,InvName: "SN: 2100443252",InvTime: "09/01/2022 17:24:59",InvStatus: "Ok",
InvTemperature: 61.460,InvGridRelay: "Closed",EToday: 20.376,ETotal: 57245.059,PACTot: 1456.000,UDC1: 254.020,UDC2: 276.090,IDC1: 4.671,IDC2: 1.087,PDC1: 1186.000,PDC2: 299.000}

MQTT yaml config

sensor:
  - platform: mqtt
    name: "SMA Output"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.status }}'
    json_attributes_topic: "sbfspot"
    
  - platform: mqtt
    name: "SMA Sunny Boy"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.InvName }}'
    icon: "mdi:flash"
    
  - platform: mqtt
    name: "SMA TimeStamp"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.Timestamp_local }}'
    icon: "mdi:clock"
    
    
  - platform: mqtt
    name: "SMA Sun Rise"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.SunRise }}'
    icon: "mdi:weather-sunny"
    
  - platform: mqtt
    name: "SMA Sun Set"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.SunSet }}'
    icon: "mdi:weather-sunset-down"
    
  - platform: mqtt
    name: "SMA Running Temp"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.InvTemperature }}'
    unit_of_measurement: "°C"
    icon: "mdi:coolant-temperature"
    device_class: temperature
    
  - platform: mqtt
    name: "SMA Status"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.InvStatus }}'
    icon: "mdi:flash"
    
  - platform: mqtt
    name: "SMA Grid Relay"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.InvGridRelay }}'
    icon: "mdi:electric-switch"
    
  - platform: mqtt
    name: "SMA Daily Energy"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.EToday }}'
    unit_of_measurement: "kWh"
    icon: "mdi:solar-power"
    device_class: energy
    state_class: total_increasing
    
  - platform: mqtt
    name: "SMA Total Energy"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.ETotal }}'
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
    
  - platform: mqtt
    name: "SMA Power AC"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.PACTot }}'
    unit_of_measurement: "W"
    icon: "mdi:flash"
    device_class: power
    state_class: measurement
    
  - platform: mqtt
    name: "SMA DC Array"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.UDC1 }}'
    unit_of_measurement: "Volts"
    icon: "mdi:solar-panel-large"
    device_class: voltage
    
  - platform: mqtt
    name: "SMA DC Array2"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.UDC2 }}'
    unit_of_measurement: "Volts"
    icon: "mdi:solar-panel"
    device_class: voltage
    
  - platform: mqtt
    name: "SMA DC Array"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.IDC1 }}'
    unit_of_measurement: "Amps"
    icon: "mdi:solar-panel-large"
    device_class: current
    
  - platform: mqtt
    name: "SMA DC Array2"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.IDC2 }}'
    unit_of_measurement: "Amps"
    icon: "mdi:solar-panel"
    device_class: current
    
  - platform: mqtt
    name: "SMA DC Array"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.PDC1 }}'
    unit_of_measurement: "Watts"
    icon: "mdi:solar-panel-large"
    device_class: power
    
  - platform: mqtt
    name: "SMA DC Array2"
    state_topic: "sbfspot_YOUR_PLANT_NAME/sbfspot_YOUR_INVERTER_SERIAL"
    value_template: '{{ value_json.PDC2 }}'
    unit_of_measurement: "Watts"
    icon: "mdi:solar-panel"
    device_class: power

I would guess the problem is in JSON format - some values (and all names) are missing quotation marks and that could cause the issue (although not sure why this only happened with core 2021.12.8, I guess the format demand was there before that).

Hmm possibly. Although it passes check config, and has been formatted the way it is for a long time now. Seems odd that’s its only the sensors too. No switches are throwing errors.

I actually rolled back to 2021.12.6 and it’s still throwing the same errors, which is odd because it was working earlier today and suddenly started throwing errors. So must be something else I’ve done.

Well, it should pass the check config, as check config does not check the source JSON for format. It merely checks, if the definition of the sensors etc is correct - which is correct in your case, only the source is not :). As I can see you only get the errors for the values missing quotation marks - the others work correctly?
Is it possible, that the source JSON changed recently?

ahh yeah I reread it as you meant source. except it is not the only sensor giving issues. Nah the errors are truncated in that list. All the sensors in that list are throwing the same error.

I have a battery powered tasmota device giving issues as well. I will have to dig around for that message. at a rough guess about 30 sensors get set up and 30 fail.

Hmm Seems like it was a stuck retained message causing the issue. reinstalled mqtt and cleared retained messages