Adding multiple sensors values into one!

difference between sensor and binary sensor? Where do you use one vs. another?

Thanks

Sensor can have various types of value, while binary_sensor can only be either on or off.

1 Like

Just as a maintenance helper you can create a separate file for the templates in the config directory.

Add the following to configuration.yaml

template: !include "yourtemplatefile".yaml

the only thing different is you don’t put “template:” in the “yourtemplatefile”.yaml as that is defined in configuration.yaml.

Great idea!
You can see here how my template.yaml is split (Frenck’s modular style). It seems a bit of a folder hunting, but I like it to be tidy :grin:

Thank you for the help yesterday. I got the hang of adding up sensor values. Now I have different question.

I have entity sensor.shunt_instantaneous_power which has both positive and negative values. I am trying to create new sensor which will display only positive values or that entity or 0 for negative values. Is that possible?

template:
  - sensor:
      - name: "Shunt Power"
        unit_of_measurement: "W"
        state: >-
          {{ ([0, states('sensor.shunt_instantaneous_power')|int, 1000] |sort) [1] }}

You can check out Taras’ explanation on how it works here-

1 Like

Thank you again. In above template 1000 can be any number I would assume? Well, I guess I will see once the solar system starts producing today. :smile:

Now for the negative values of the shunt measurement. How can that negative value be converted into positive. Reason for my asking is because of the requirement of this card Tesla Style Card

From git hub page:

**templates for missing sensors or for negative sensors

Remember you can create template sensors if you are missing one like solar yield out of solar_consumption and grid_feed_in or if you are missing another one like home_consumption. Some inverters have positive and negative values, here all sensors need to be positive values, so create template sensors like:

battery_consumption:
    value_template: '{% set batter_cons = sensor.powerwall_battery_now | int %}
                    {% if batter_cons > 0 %}
                        {{ batter_cons | int }}
                    {% else %}
                        0
                    {% endif %}'
    device_class: power
    unit_of_measurement: W**

I need to buy you a beer :beer:

Try using abs filter-

{{ states('sensor.powerwall_battery_now') | int | abs }}

2 Likes

Solution to show Power Wall (negative) discharge values of the sensor as positive and showing 0 for all the positive values of the sensor. It works. Thank you again. Would you change anything?

template:
  - sensor:
      - name: "PWdischarge Tesla"
        unit_of_measurement: "W"
        state: <-
          {{ ([-30000, states('sensor.shunt_instantaneous_power')|int, 0] |sort) [1] | abs }}

I have similar question. I would like to have data from multiple sensors and get mean value, but statistics platform does not support multiple entities. Any ideas for this?

 - platform: statistics
    entities:
      - sensor.mijia_1_temperature
      - sensor.temperature_19
    sampling_size: 2
    name: livingroom_mean
    max_age:
      minutes: 30

I use min max

sensor:
  - platform: min_max
    name: "Main Floor Average Temperature"
    type: mean 
    round_digits: 1
    entity_ids:
      - sensor.multisensor_6_air_temperature
      - sensor.kitchen_flood_sensor_air_temperature_2
      - sensor.main_floor_temperature
      - sensor.mil_bath_leak_sensor_air_temperature_2
      - sensor.mud_room_fibaro_air_temperature_2
1 Like

I have very similar code and I am getting unknown error when I look at it in developers tools.
My code is:

sensor:
  - platform: min_max
    entity_ids:
      - sensor.17_seaview_avenue_current_temp
      - sensor.dark_sky_current_temp
      - sensor.tasmota_outside_temp_ds18b20_temperature_2
    type: mean
    round_digits: 1
    name: Outside_Aveage_Temp

All three of the sensors give a reading in developers tools. Any ideas how to troubleshoot this?
Mine now works.
The issue I had was the default unit of measure on the template sensors was different.

got a question on this… (hoping I just missed something in my config…)
I am getting a phantom watt reading when all lights are off:

image

Here’s my template for this:

and when some of the lights are on…
image

… Also noticed even when a bulb is “OFF”, it shows a reading of 0.4 W (is this my issue and maybe just a residue/discharge of energy for zigbee?)

I would assume it’s from the power draw of the smart plug itself (radio, LED, etc). Commonly called “vampire load”.

I know this is a bit of a necro but I wanted to say thanks! This was the best example I found for this, and is still relevant in 2023.

Cheers!

My Yaml template cannot being used as it’s a non-numeric value

Screenshot 2023-07-31 at 14.02.48

My code is like this:

template:
  - sensor:
      - name: "current_power_usage"
        unit_of_measurement: "W"
        device_class: power
        state: >
          {{ [ states('sensor.phase_a_power')| float(0) + 
               states('sensor.phase_b_power')| float(0) +
               states('sensor.phase_c_power')| float(0) +
               states('sensor.envoy_solar_panels_current_power_production')| float(0)] }}
        availability: >
          {{ not 'unavailable' in 
             [ states('sensor.phase_a_power'), 
               states('sensor.phase_b_power'),
               states('sensor.phase_c_power'),
               states('sensor.envoy_solar_panels_current_power_production')] }}

It’s probably simple, but what can I do to use it in a Gauge?

Because you’re returning a list…


        state: >
          {{ states('sensor.phase_a_power')| float(0) + 
             states('sensor.phase_b_power')| float(0) +
             states('sensor.phase_c_power')| float(0) +
             states('sensor.envoy_solar_panels_current_power_production')| float(0) }}
Application of this format generated  this errormessage in dev_tools:

ValueError: Template error: float got invalid input 'unknown' when rendering template 

template:
  -sensor:
      - name: "Total Charging Power"
        unit_of_measurement: "W"
        device_class: power
        state: >
          {{ [ states('sensor.sessy_d5mr_charge_power' ), 
               states('sensor.sessy_dma4_charge_power' )]
               | map('float') | sum }}
        availability: >
          {{ not 'unavailable' in 
             [ states('sensor.sessy_d5mr_charge_power'), 
               states('sensor.sessy_dma4_charge_power') ] }}' 

but no default was specified.

How to solve?
Or just an initialisation issue?

map('float', default=0)

You should start a new topic in future for new issues.

Thanks!
Will do …