MQTT sensors out of phase

Hi,

I have a tasmotised Sonoff POW v2.0 (not R2) with the following sensors set up and working:

- platform: mqtt
  name: 'Ensuite Energy Today'
  state_topic: 'tele/sonoff13/SENSOR'
  value_template: "{{ value_json['ENERGY'].Today }}"
  unit_of_measurement: 'kWh'
- platform: mqtt
  name: 'Ensuite Power'
  state_topic: 'tele/sonoff13/SENSOR'
  value_template: "{{ value_json['ENERGY'].Power }}"
  unit_of_measurement: 'W'
- platform: mqtt
  name: 'Ensuite Voltage'
  state_topic: 'tele/sonoff13/SENSOR'
  value_template: "{{ value_json['ENERGY'].Voltage }}"
  unit_of_measurement: 'V'
- platform: mqtt
  name: 'Ensuite Current'
  state_topic: 'tele/sonoff13/SENSOR'
  value_template: "{{ value_json['ENERGY'].Current }}"
  unit_of_measurement: 'A'
- platform: mqtt
  name: 'Ensuite Sensor'
  state_topic: 'tele/sonoff13/SENSOR'
  json_attributes_topic: 'tele/sonoff13/SENSOR'
  value_template: >
    {% set ens=states.sensor.ensuite_sensor.attributes.ENERGY %}
    {{ens.Power}}W/
    {{ ens.Voltage}}V/
    {{ ens.Current}}A/
    {{ ens.Today}}kWh

The first 4 sensors work as expected and respond well to changes and switching ON/OFF.

The 5th sensor is out of phase with the others.

24

36

Can’t figure out what’s happening. Any ideas would be most welcome.

Thanks

You can’t grab information from yourself if yourself hasn’t been created. So this will always be out of sync forever. Gotta grab the info from the json.

- platform: mqtt
  name: 'Ensuite Sensor'
  state_topic: 'tele/sonoff13/SENSOR'
  json_attributes_topic: 'tele/sonoff13/SENSOR'
  value_template: >
    {% set ens = value_json['ENERGY'] %}
    {{ ens.Power }}W/
    {{ ens.Voltage }}V/
    {{ ens.Current }}A/
    {{ ens.Today }}kWh

Thanks for the heads up. I realised that shortly after I posted. Is there a way to grab the info in one go instead of having the four sensors?

Depends on what you want to do with them in the end. If you want to display them nicely in the UI, keep them separate and you’ll have a ton of options.

At this time I just want to display the info.

The ‘combined method’ will only use one sensor and take up less space on the front end than four separate sensors.

Data is still available for automations and such from the combined sensor, no?

it is, but you’d have to template everything for automations. You wouldn’t be able to use normal triggers, you’d have to use template triggers, and for conditions you’d have to use template conditions. Every time you wanted one of the values from the combined sensor, you’d have to parse it out using code. Do you want to do that all for the sake of a condensed interface? Not to mention, you can build a condensed interface with other card types. The entity card just displays it in that long form that you posted.

I guess you are right.

Thank you for your insight.

Separate sensors it is then.