Sensor values not showing/pickable in energy setup

Hi hi all

I’m seeing none of my desired entities/sensors in the Energy configuration screen…

Is there a specific setting that I need to set to have my sensors visible.

G

Go to Developer Tools → States.

Copy the attributes from one of the sensors and paste it here.

1 Like

posting my solar_yield and battery_power, which is current power output from battery as 2 examples.


The second sensor is a power sensor. The energy dashboard uses energy sensors. Energy and power are not the same thing.

The first one is an energy sensor with the correct unit and device_class however it is missing a state_class of total, or total_increasing.

How was this energy sensor added to home assessment?

Hi Tom,
Both are via definitions in configuration.yaml as mqtt based sensor inputs, data originating from my Victron Inverter via a NodeRed flow.
G

Please show the energy sensor config (correctly formatted).

not exactly suer what you want to see, but here goes…
My value for solar yield as mentions come from a topic that my inverter exposes via mqtt, see attached.
thats the inbound value on the way to HA onto a mqtt topic, from where I then consume and as per code block below.

**from configuration.yaml**
     # Solar PV
   - state_topic: "victron/system/0/Dc/Pv/Power"
     name: "Solar Yield"
     unit_of_measurement: 'Wh'
     value_template: "{{ value_json.value | round(0) }}"
     device_class: power

Ok, that should be:

   - state_topic: "victron/system/0/Dc/Pv/Power"
     name: "Solar Yield"
     unit_of_measurement: 'Wh'
     value_template: "{{ value_json['value'] | round(0) }}"
     device_class: energy
     state_class: total_increasing

I changed the wrong device class and added a state class.

I’m surprised it worked at all as value_json.value is not a valid template. value is a reserved word that returns the raw message value, not the json key value. I have changed it to the required square bracket notation above.

Busy chasing the solar_yield and battery_yield… and grid supply, but noticed the solar _yield was tagged Wh… looking at source it’s actually just current W output… looking for a Wh feed.

Ok, so that’s just a power sensor then.

If the Victron node red flow does not supply energy sensors you can integrate power with respect to time using this:

Feed your power sensors to this and it will count the energy for you.

Make sure your power sensors have the correct attributes:

Power sensor:

device_class: power
state_class: measurement
unit_of_measurement: W # or kW

And make sure you use method: left in the Riemann Sum config.

The Riemann Sum integration should hen generate an energy sensor with the following attributes:

device_class: energy
state_class: total_increasing # or total
unit_of_measurement: Wh # or kWh

These are the attributes of an energy sensor required for use in the energy dashboard.

busy going through everything, set those sensors back to original and will be using your above integration to calculate energy.

Can you advise, using your block notation how this should actually be:

value_template: "{{ value_json.ENERGY.Power | round(0) }}" 

Will feed back. thanks

EDIT: The post below is wrong. It is a key called “values” that is problematic. Not “value”. It’s a method. Other methods that could cause issues when used as key names:

'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'

That one is ok. It’s only the templates that use value_json with the the key value in them that are the issue: value_json.value

json serialised messages are formatted in value: key pairs, like this { "voltage" : 244 }, voltage is the key, 244 is the value. The problem occures when the key is called “value”, like { "value" : 597.16 }

In an mqtt template these variables have specific meanings:

value_json = parse the message as a json formatted message

value = return the entire message as raw text.

So value_json.value means find the key in the json serialised message that matches the whole message. Which is of course recursive and impossible.

So by using square brackets around “value” we tell home assistant that this is to be interpreted as a key and not the entire raw mqtt message.

1 Like

Instead of using the UI for helper functions to do the power to energy conversion I want to use code def in configuration.yaml, however even though the file editor gives tick mark, Developer Tools - Yaml check Configuration is not liking this…

  - state_topic: "victron/system/0/Ac/Consumption/L1/Power"
    name: "Total Consumption"
    value_template: "{{ value_json['value'] | round(1) }}"
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    
  - platform: integration
    source: sensor.total_consumption
    name: total_consumption_energy
    unit_prefix: k
    round: 2

This part goes under sensor: (or in sensors.yaml if you have an !include file) not under mqtt:

remember the entire structure of the configuration.yaml got changed a while back…

this is how mine is now…


mqtt:
  
  binary_sensor:
    - state_topic: "home/eskom/connected"
      name: "Eskom Supply"
      value_template: "{{ value_json.value }}"
      payload_on: "ON"
      payload_off: "OFF"
      device_class: connectivity
    
    - state_topic: "victron/battery/charging/state"
      name: "Battery Charging Status"
      value_template: "{{ value_json.value }}"
      payload_on: "ON"
      payload_off: "OFF"
      device_class: battery_charging


    
  # https://developers.home-assistant.io/docs/core/entity/sensor
  sensor:
  - state_topic: "home/WaterTankLevels/CouncilWaterTank1/json"
    name: "CouncilWaterTank1-PercentageFilled"
    unit_of_measurement: '%'
    value_template:  "{{ value_json.fields.fill_percentage }}"

    #### VICTRON #####
    # Total Consumption
  - state_topic: "victron/system/0/Ac/Consumption/L1/Power"
    name: "Total Consumption"
    value_template: "{{ value_json['value'] | round(1) }}"
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    
  - platform: integration
    source: sensor.total_consumption
    name: total_consumption_energy
    unit_prefix: k
    round: 2

Ok I see the confusion. That sensor block is part of the mqtt integration. We need to put the Riemann sum sensor platform under the sensor integration. Riemann Sum is not part of mqtt.

Look for the word sensor: hard up against the left hand column, like mqtt: is. That’s where it goes. Unless it says this:

sensor: !include sensors.yaml

Then you need to put it in sensors.yaml.

ok, I actually have no sensors up against the left, as all my sensor feed is from mqtt.

I can I run a sensor block under mqtt and also a standalone next to the left margin.

G

Yes you can:

mqtt:
  
  binary_sensor:
    - state_topic: "home/eskom/connected"
      name: "Eskom Supply"
      value_template: "{{ value_json.value }}"
      payload_on: "ON"
      payload_off: "OFF"
      device_class: connectivity
    
    - state_topic: "victron/battery/charging/state"
      name: "Battery Charging Status"
      value_template: "{{ value_json.value }}"
      payload_on: "ON"
      payload_off: "OFF"
      device_class: battery_charging


    
  # https://developers.home-assistant.io/docs/core/entity/sensor
  sensor:
  - state_topic: "home/WaterTankLevels/CouncilWaterTank1/json"
    name: "CouncilWaterTank1-PercentageFilled"
    unit_of_measurement: '%'
    value_template:  "{{ value_json.fields.fill_percentage }}"

    #### VICTRON #####
    # Total Consumption
  - state_topic: "victron/system/0/Ac/Consumption/L1/Power"
    name: "Total Consumption"
    value_template: "{{ value_json['value'] | round(1) }}"
    device_class: power
    state_class: measurement
    unit_of_measurement: W

sensor:
  - platform: integration
    source: sensor.total_consumption
    name: total_consumption_energy
    unit_prefix: k
    round: 2
1 Like

ok,

i’m just out quickly, will try and reshape as per above.

thanks for all the advise.

G

1 Like

awesome… values working…

just now have to figure out how to determine energy going into battery vs coming out.
as I only have a single feed thats either + or - and a different field that says idle/charging/discharging.

thank you, same some gr8 progress here.

G