Formatting mqtt payload differences

Dear all,

I read the values: consumption high and low tariff and injection high and low tariff harvested from my P1 meter over mqtt.
In my dashboard both the values of injection differ from both the consumption values, the injection has 3 decimals, the consumption has 2 decimals but al the payloads are divided by 1000.

The P1.yaml file

mqtt:
  sensor:
    - name: P1 Consumption High Tariff
      unique_id: 'sensor.p1_consumption_high_tariff'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      state_topic: "sensors/power/p1meter/consumption_high_tarif"
      value_template: "{{ value|float / 1000 }}"

    - name: P1 Return Delivery Low Tariff
      unique_id: 'sensor.p1_delivery_low_tariff'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      state_topic: "sensors/power/p1meter/returndelivery_low_tarif"
      value_template: "{{ value|float / 1000 }}"

    - name: P1 Consumption Low Tariff
      unique_id: 'sensor.p1_consumption_low_tariff'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      state_topic: "sensors/power/p1meter/consumption_low_tarif"
      value_template: "{{ value|float / 1000 }}"

    - name: P1 Return Delivery High Tariff
      unique_id: 'sensor.p1_delivery_high_tariff'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      state_topic: "sensors/power/p1meter/returndelivery_high_tarif"
      value_template: "{{ value|float / 1000 }}"

the dashboard:

type: entities
entities:
  - entity: sensor.p1_consumption_high_tariff
    name: Verbruik dag
  - entity: sensor.p1_consumption_low_tariff
    name: Verbruik nacht
  - entity: sensor.p1_return_delivery_high_tariff
    name: Geleverd dag
  - entity: sensor.p1_return_delivery_low_tariff
    name: Geleverd nacht
title: kWh meter

The results of the numbers:

There are no particular error messages in the “file editor” logfile .

If I check the payload with mqtt studio they are all 7 digit numbers without decimal point or comma.

What am I doing wrong or missing?

Thx

You’re not doing anything wrong. It simply doesn’t display trailing zeros.

In other words, by default, it does this:

1.5

Not this:

1.50

If you want to force the sensor’s value to always be displayed with 3 decimal places (or whatever amount you want) change it in the sensor’s configuration.

  1. Go to Developer Tools → States
  2. Find the sensor’s entity_id
  3. Click the information icon next to its entity_id
  4. Click the gear icon in the upper right corner
  5. Change “Display Precision”
  6. Click the Update button

Based on how you configure it (2 or 3 decimal places), you can make 6.591,56 appear as 6.591,560 or 6.290,798 as 6.290,80.

2 Likes

Thanks a lot, that solved it.

Sorry for the typo’s in my message: difference in p1.yaml and the dashboard between the unique_id and the entity.

1 Like