Groups, views, sensors and templates - want a view with sensor info

Hi all

I want to have a group, in which is my switch (TPLink) and the associated sensor information.

The code i have for the sensors is here

sensor:
# Weather prediction
  - platform: yr
  - platform: template
    sensors:
      my_tp_switch_pool_amps:
        friendly_name_template: "{{ states.switch.Pool.name}} Current"
        value_template: '{{ states.switch.Pool.attributes["current_a"] | float }}'
        unit_of_measurement: 'A'
      my_tp_switch_pool_watts:
        friendly_name_template: "{{ states.switch.Pool.name}} Current Consumption"
        value_template: '{{ states.switch.Pool.attributes["current_power_w"] | float }}'
        unit_of_measurement: 'W'
      my_tp_switch_pool_total_kwh:
        friendly_name_template: "{{ states.switch.Pool.name}} Total Consumption"
        value_template: '{{ states.switch.Pool.attributes["total_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'
      my_tp_switch_pool_volts:
        friendly_name_template: "{{ states.switch.Pool.name}} Voltage"
        value_template: '{{ states.switch.Pool.attributes["voltage"] | float }}'
        unit_of_measurement: 'V'
      my_tp_switch_pool_today_kwh:
        friendly_name_template: "{{ states.Pool.name}} Today's Consumption"
        value_template: '{{ states.switch.Pool.attributes["today_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'

And my group config is here

group:
  deck:
    name: Deck
    view: yes
    entities:
      - switch.DeckLights
  pool:
    name: Pool
    view: yes
    entities:
      - switch.Pool
  study:
    name: Study
    view: yes
    entities:
      - switch.MiniITX

How do i marry the two?

I want the “Study” view/group to have the switch for a miniITX system, and display on that page the output that is generated from the code in the sensor/template above.

I have done some googling, but couldnt seem to see the answer. And might not have my head around templates and if what i want to do is even possible.

Thanks!

You just add the sensors to the group, like so:

group:
  deck:
    name: Deck
    view: yes
    entities:
      - switch.DeckLights
  pool:
    name: Pool
    view: yes
    entities:
      - switch.Pool
  study:
    name: Study
    view: yes
    entities:
      - switch.MiniITX
      - sensor.my_tp_switch_pool_amps
      - sensor.my_tp_switch_pool_watts
      - sensor.my_tp_switch_pool_total_kwh
      - sensor.my_tp_switch_pool_volts
      - sensor.my_tp_switch_pool_today_kwh

I guessed the sensor entity ids from your config. Very likely correct but to be 100% sure you should check the developer tools states menu.

Ha! Thanks tom_l :slight_smile:

I must have had the syntax very slightly wrong, or maybe my hass is a bit flakey.

Added the suggestion, and its displaying just how i’d like.

So the sensor data for watts amps etc is a standard set of data that is pulled from the TPLink plugs via those calls?

I guess what i am asking is do i need it in the sensors section at all, i.e. does it need to be defined there? or can I just call for that data in each view i want it in?

Appreciate the help mate !

The sensors are defined in the sensors section you posted. I just listed their entity_ids so they show up in the group you wanted.

You definitely need the sensors defined in in the sensor: section of your configuration.yaml file if you want to to use or view them elsewhere. The list of sensors in the group is just a pointer to those definitions.