Creating a new sensor and populate it with attributes from 3 other sensors? Can it be done?

Is it possible to create a new sensor let’s say sensor.tesla.car and populate it with states or attributes from different other sensors? So you’d get:
sensor. tesla.car
with attributes:
one
two
three

Which would populate from 3 different other sensors that already exist.
sensor. car.charge_level [state]
sensor.light.room [level attribute]
sensor.motion.outside [humidity attribute]

Did I make myself clear? I think I did. I can’t find this anywhere.

Yes the template sensor supports attribute templates as well as the state template.

https://www.home-assistant.io/integrations/template/#attributes

I know the template sensor supports attributes. But I want to take 3 or 4 attributes from 3 or 4 different sensors and create one new sensor with all these attributes in it.
So if I have a temp of 34 with a battery level of 56% and a motion sensor ON
Then i’d like to create a new sensor that has attributes [34, 56, ON]
Basically

You can do that.

State template: Tesla car state

Attribute templates: states from the 3 or 4 other sensors.

Could you show me what it looks like in yaml?
Would this work?

sensor:
  - platform: template
    sensors:
      my_new_sensor:
        value_template: "OK"
        attribute_templates:
          attribute1: "{{ states('sensor.sensor1') }}"
          attribute2: "{{ states('sensor.sensor2') }}"
          attribute3: "{{ states('sensor.sensor3') }}"

For new sensors it is recommended that you use the new format.

configuration.yaml:

template:
  - sensor:
      - name: my new sensor
        state: "OK" # you can also put a state template here
        attributes:
          attribute1: "{{ states('sensor.sensor1') }}"
          attribute2: "{{ states('sensor.sensor2') }}"
          attribute3: "{{ states('sensor.sensor3') }}"
1 Like

Got it
Thanks. It worked.