#Make a calculation of two entities
1 messages · Page 1 of 1 (latest)
Yes it's possible, complexity will vary depending on a few things
- 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) - 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, addnot_fromandnot_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 - Works with variable cost, but requires more helpers
- Derivative helper pointed at your
energy_sensorto 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
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.
thanks will take a look
not sure i follow this one i can add my usage entity as grid consumption and set a static rate (which it is) but then it doesnt show me the months total but some other total. Maybe thats being skewed by being in now view?
the indivirual item stuff shows usage for period but dont see a way to add price.
yes, the total is based on your current view
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
I wrote an example here: 11. How can I display historical energy cost or consumption in a timeseries chart?