Powercalc - Virtual power sensors

What does mean Error Unable to prepare setup for platform powercalc.sensor: (DependencyError(...), 'Could not setup dependencies: device_tracker')

Thanks @bramski for the excellent work, and your super quick turnaround on reported issues. I wrote a blog post with details of how I used Powercalc to use to monitor power consumption of 60 out of 69 devices in my house. I included my full config, in case its useful to anyone. Virtual Energy Meters with PowerCalc - Sean Blanchfield's Blog

1 Like

Very strange because the device_tracker integration is a core integration. Powercalc waits for this integration to load succesfully before it starts it’s own setup. Any other errors in the logs? I have no clue really.

@seanblanchfield Awesome write up! Cool to see you are using the component this extensive and you got great results. This gives you a lot of insight into power consumption across your house and discover opportunities to save energy.

I also don’t know what is the connection between device_tracker and Powercalc.

2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of powercalc. Setup failed for dependencies: device_tracker
2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Setup failed for powercalc: (DependencyError(...), 'Could not setup dependencies: device_tracker')
2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of powercalc. Setup failed for dependencies: device_tracker
2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform powercalc.sensor: (DependencyError(...), 'Could not setup dependencies: device_tracker')
2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of powercalc. Setup failed for dependencies: device_tracker
2022-02-24 21:00:07 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform powercalc.sensor: (DependencyError(...), 'Could not setup dependencies: device_tracker')

Did powercalc work for you before or did you always get this error?

This is one of the dependencies of powercalc. I have added that because you can also create power sensors based on the state of device trackers. To make sure the device_tracker entities are created before powercalc entities.
I did test on my development machine and it seems without this dependency it is also working. So I think it can be safely removed. Will do that soon.

Fingers crossed you are right because I use the device_tracker functionality

Are you able to test this on your instance as well, by removing device_tracker from manifest.json and restarting HA?

Yes started up ok…although I did just realise I am not currently using the device_tracker option as I put a power meter on that device.

Hey! First of all thank you, awesome plugin!

I’m trying to do something but it seems I don’t know how!

I have my Smart TV which is connected to the Home Assistant and also i have the Soundbar which is not smart so i have nothing related to it in the home assistant. But the soundbar it’s always the same state as the TV.

So I have added a sensor for the TV:

- platform: powercalc
  entity_id: media_player.upstairs_living_tv
  standby_power: 0.5
  fixed:
    power: 100
    states_power:
      source|Live TV: 110
      source|XBOX: 140

And then I wanted to create a new sensor for the Soundbar which uses the state of the same entity_id (the tv) but unfortunately i can’t do this.

This is how i tried to do it:

- platform: powercalc
  name: Upstairs Living Soundbar
  unique_id: upstairs_living_soundbar
  entity_id: media_player.upstairs_living_tv
  standby_power: 3.5
  fixed:
    power: 20

It’s there any way I could create this sensor based on the state of TV?

Thank you!

Currently only a single powercalc configuration is allowed per entity_id.

For now you could solve this by introducing a template sensor sensor.upstairs_living_soundbar which just returns the state of media_player.upstairs_living_tv. And than use this template sensor as an input for Upstairs Living Soundbar.
Another approach would be to just add 3.5 to the TV consumption.

I understand your usecase and would be useful if this was supported by powercalc without the need of an extra entity. Could you create a feature request on the github issue tracker for this? I am not sure if I will be able to do it because there is a reason I put this limitation in place.

Perfect! Don’t know why I didn’t think of that :slight_smile:! Thank you

In the end, maybe is having the same question, i did it like this:

Create a Template Sensor with the same state as the TV

template:
  - sensor:
      - name: Upstairs Living Soundbar
        unique_id: upstairs_living_soundbar
        state: "{{ states('media_player.upstairs_living_tv') }}"   

Then add a powercalc sensor for that entity

- platform: powercalc
  entity_id: sensor.upstairs_living_soundbar
  standby_power: 3.5
  fixed:
    power: 20   
2 Likes

I can’t seem to get a group sensor working.

I have the following under sensors:

  - platform: powercalc
    create_group: all kitchen lights
    entities:
      - entity_id: light.kitchen

light.kitchen is a group created by Hue.

I have auto discovery enabled in global config, so i don’t have defined entities for each light:

powercalc:
  enable_autodiscovery: true
  scan_interval: 00:01:00 #Each minute
  create_energy_sensors: true
  create_utility_meters: true
  utility_meter_types:
    - hourly
    - daily
    - weekly
    - monthly
    - yearly

Could this be causing the issue?

My understanding is that i should get a sensor.all_kitchen_lights_power ?

Edit: I’ve just tried with an entity for one of the lights rather than a group of lights and that appeared to work fine.

The create_group purpose is to create an aggregate power and energy sensor for all underlying individual entities. As you already discovered entity_id always must be an individual light.
With the include functionality you have an option to automatically include all entities of a light group, but I am not sure if this is working for Hue groups already. Could be that it only works for native HA light groups. I am unable to test this atm, but will have a look into that because that seems useful to me.

Thanks for the quick reply.

I could probably get away with include area, i can see include group would require setting up a group config which would probably add more lines to the config than just adding the individual light entities.

Just wanted to let you know I added a new function to powercalc which will make your life easier.

Now it’s possible with a one liner to create a group sensor for all powercalc entities of a given domain, for example “light”.

You can do that as follows:

powercalc:
  create_domain_groups:
    - light

This will create a sensor “All light power”, and also energy and utility_meters.

Has been released in latests beta v0.19.0-beta.2.

Btw. this will add ALL lights to the group sensor. When you want more granular control you need to use the existing way to create groups.

2 Likes

Hi bramski, thanks for this, it was exactly what I have been looking for!

I have just updated to v0.19.0-beta.2 and added that to my config and it has created the new group total entity.

I can’t seem to use the group on the energy dashboard since it doesn’t seem to have a corresponding “statistic”. All the other “energy” entities added by powercalc have statistics.

You have to wait a bit to have statistics gathered. Should appear after an hour or something like that. Does it work now?

Unfortunately not, all other powercalc energy entities have statistics, but not the powercalc.all_light_energy one.

Hmm ok. Could you create an issue on github please? Will have a look into this next weekend.

1 Like