Jeg har disse feltene:
Disse 2 sensorene:
accumulatedconsumption:
friendly_name: "Akkumulert forbruk"
unit_of_measurement: 'kWh'
device_class: power
value_template: "{{ state_attr('sensor.real_time_consumption_gabriel_edlands_veg_16', 'accumulatedConsumption') | round(2) }}"
accumulatedcost:
friendly_name: "Kostnad"
unit_of_measurement: 'NOK'
value_template: "{{ state_attr('sensor.real_time_consumption_gabriel_edlands_veg_16', 'accumulatedCost') | round(2) }}"
Og denne koden som lett kan lages som en mal-sensor (hvorfor har jeg ikke det, da......)
def calculate(self, entity, attribute, old, new, kwargs):
try:
total = float(self.get_state("sensor.accumulatedcost"))
total += float(self.get_state("sensor.accumulatedconsumption")) * float(self.get_state("input_number.pris_pr_kwh_kleppenergi")) / 100
total += float(self.get_state("input_number.pris_pr_aar_kleppenergi")) / 365
total += float(self.get_state("input_number.pris_pr_aar_tibber")) / 365
self.set_state("sensor.total_pris_for_strom", state = "{:3.2f}".format(total), attributes = {"unit_of_measurement": "NOK"})
except ValueError:
pass