Combine sensors as template

Hi all,

I understand the legacy sensor template is being depreciated and I am trying to update two sensors to the modern format before they get removed entirely but I’m having issues doing so, I don’t get any errors when checking the config but the new sensors just don’t appear as an entity, my legacy sensors work fine without issue and wondering why they don’t appear anyone able to see what I am doing wrong? (No doubt it’s obvious lol)

System info:

  • version: core-2021.12.9

  • installation_type: Home Assistant OS

  • dev: false

  • hassio: true

  • docker: true

  • user: root

  • virtualenv: false

  • python_version: 3.9.7

  • os_name: Linux

  • os_version: 5.10.88

  • arch: x86_64

  • host_os: Home Assistant OS 7.1

  • update_channel: stable

  • supervisor_version: supervisor-2021.12.2

  • docker_version: 20.10.9

  • disk_total: 30.8 GB

  • disk_used: 9.9 GB

  • healthy: true

  • supported: true

  • board: ova

  • supervisor_api: ok

  • version_api: ok

  • installed_addons: Samba share (9.5.1), Mosquitto broker (6.0.1), Terminal & SSH (9.3.0), File editor (5.3.3), Node-RED (10.3.2), ESPHome (2021.12.3), Samba Backup (5.0.0), Studio Code Server (4.0.0), SQLite Web (3.2.0)

  • resources: 27

This method still doesn’t work:
N/B this is the method I would prefer to use if I can get working so I can split out my files

#####
# Template Sensors for gathering information about states and conditions.
#
# This loads up template configurations
#
#https://www.home-assistant.io/integrations/template
#####

template: !include_dir_list ../entities/templates

/entites/templates/eth_val.yaml

#####
# Converts Eth value attribute to sensor for use
#####

sensor:
  - name: Eth Value
    state: '{{ states.sensor.coinbase_eth_wallet.attributes["Balance in native currency"] }}'

/entites/templates/lr_total_power.yaml

#####
# Combines two sensors to create a new one for total power in the living room
#####
sensor:
  - name: living room power total
    entity_id:
      - sensor.tv_plug_power
      - sensor.shellycolorbulb_e8db84aa63be_power
    state: "{{ (states('sensor.tv_plug_power')|float + states('sensor.shellycolorbulb_e8db84aa63be_power')|float) }}"
    unit_of_measurement: "W"

This method one template works but the new one doesn’t:

#####
# Template Sensors for gathering information about states and conditions.
#
# This loads up template configurations
#
#https://www.home-assistant.io/integrations/template
#####

template: !include_dir_merge_list ../entities/templates

My understanding is by using merge list that all items go in the same config file and it should merge them all in, if I do this, the ‘Eth Val’ entry works but the ‘living room total power’ doesn’t?

/entites/templates/eth_val.yaml


  - sensor:
      - name: Eth Value
        state: '{{ states.sensor.coinbase_eth_wallet.attributes["Balance in native currency"] }}'

  - sensor:
      - name: living_room_power_total
        entity_id:
          - sensor.tv_plug_power
          - sensor.shellycolorbulb_e8db84aa63be_power
        state: "{{ (states('sensor.tv_plug_power')|float + states('sensor.shellycolorbulb_e8db84aa63be_power')|float) }}"
        unit_of_measurement: "W"

To throw a spanner in the works, this one does work as a sensor but that is being killed off soon so I want to move it before that happens
sensors:

#####
# Sensors are gathering information about states and conditions.
#
# This loads up sensor configurations
#
# https://www.home-assistant.io/integrations/sensor
#####

sensor: !include_dir_list ../entities/sensors

/entites/sensors/system/livingroom_total_power.yaml

#####
# Total live power usage of living room
# https://community.home-assistant.io/t/combine-values-of-three-sensor/121654/3
#####

platform: template
sensors:
  living_room_power_total:
    friendly_name: 'Total Living Room Power'
    entity_id:
      - sensor.tv_plug_power
      - sensor.shellycolorbulb_e8db84aa63be_power
    value_template: "{{ (states('sensor.tv_plug_power')|float + states('sensor.shellycolorbulb_e8db84aa63be_power')|float) }}"
    unit_of_measurement: "W"

No matter which option I go with I get an error in my logs which doesn’t make sense, it complains about a syntax error on a line which is blank and if I remove all lines above the entry then the error goes to line 0?

Invalid config for [template]: [entity_id] is an invalid option for [template]. Check: template->sensor->0->entity_id. (See /config/integrations/…/entities/templates/lr_total_power.yaml, line 3).

I know it’s complaining about entity ID’s but how would I add up two sensors without specifying them as historically you had to?

Hope I’ve provided enough info and not gone overboard.

TLDR
Can’t convert a legacy sensor template to a modern template sensor:

#####
# Combines two sensors to create a new one for total power in the living room
#####
sensor:
  - name: living room power total
    entity_id:
      - sensor.tv_plug_power
      - sensor.shellycolorbulb_e8db84aa63be_power
    state: "{{ (states('sensor.tv_plug_power')|float + states('sensor.shellycolorbulb_e8db84aa63be_power')|float) }}"
    unit_of_measurement: "W"

Ignore me, figured out I was doing something stupid in that I don’t need to actually specify the entities before creating the state