#Make a calculation of two entities

1 messages · Page 1 of 1 (latest)

steel summit
#

Hi all, im fairly new to all this and trying to work out if its possible to do something. I have one entity giving me per kwh cost and another with kwh consumed this month.

I want to multiply them together to give me cost this month and then ideally show on dashboard. Is this possible?

spiral phoenix
#

Yes it's possible, complexity will vary depending on a few things

  1. Simplest solution: constant price per kWh - make a template sensor helper and multiply the two numbers with {{ states('sensor.cost_sensor') | float(0) * states('sensor.energy_sensor') | float(0) }} (rename the sensors to whatever your entities are called obviously)
  2. Complicated but works with variable price solution
    You need to make a triggered template sensor (this has to use your configuration file, can't do it in the UI sadly)
    trigger - state trigger on your energy sensor changing, add not_from and not_to "unknown" and "unavailable"
    sensor - template sensor that adds the change in state * current cost to its current value to get a running total. not able to test this atm but it should look something like {{ (this.state | float + (trigger.to_state.state | float - trigger.from_state.state | float) \* states('sensor.energy_sensor') | float(0) }}
    You can add in an additional trigger to get this to reset at the start of every month (trigger at midnight, check if today's day of the month is 1, reset) but honestly, using a utility meter helper to get a resetting value is far simpler
  3. Works with variable cost, but requires more helpers
  • Derivative helper pointed at your energy_sensor to get current power (can be skipped if you have a power entity provided)
  • Template sensor: multiply the current power by the cost/kWh - this gives you a cost/hour
  • Integral helper: integrate your cost/hour to get a running cost
  • Utility Meter Helper: point it at your integral sensor to allow you to get a value that resets every month
slim linden
#

You don't need any of that. Just add your kWh entity and your cost/kWh entity to the energy dashboard and it will automatically generate a cost entity for you that calculates the total cost.

steel summit
#

the indivirual item stuff shows usage for period but dont see a way to add price.

slim linden
#

but the sensor it generates (ends with *_cost) can be used anywhere

#

so you can make your own charts as long as you have the cost sensor