jmcollin78 / solar_optimizer

The Solar Optimizer integration for Home Assistant starts and stops your equipments depending on the Solar net production
MIT License
53 stars 10 forks source link

Support day/night tariff sensor for energy buy price #12

Closed stijnb1234 closed 6 months ago

stijnb1234 commented 6 months ago

Is your feature request related to a problem? Please describe. My energy supplier has day/night tariffs.

Describe the solution you'd like I can set the tariff in an input_number for day and night and switch between them in a template sensor, but it's not possible to set a sensor as 'Energy buy price' parameter because it requires an input number.

Please consider also supporting a sensor value for this so that you can use a template for this.

Describe alternatives you've considered It's possible to create an input number and update that every minute using an automation, but that's not very efficient.

Example implementation of the sensor (not directly related to this issue!):

input_number:
  energy_usage_cost_tariff_1:
    name: Energy Usage Cost Tariff 1
    icon: mdi:currency-eur
    initial: 0.1 #whatever tariff in 1
    min: 0
    max: 1
    step: 0.01

  energy_usage_cost_tariff_2:
    name: Energy Usage Cost Tariff 2
    icon: mdi:currency-eur
    initial: 0.2 #whatevery tariff in 2
    min: 0
    max: 1
    step: 0.01

sensor:
  - platform: template
    sensors:
      current_energy_tariff:
        friendly_name: "Current Energy Tariff"
        value_template: >-
          {% set n = as_timestamp(now()) %}
          {% set peak_start = as_timestamp(now().replace(hour=7, minute=0, second=0)) %}
          {% set peak_end = as_timestamp(now().replace(hour=23, minute=0, second=0)) %}
          {% set is_peak_hours = n >= peak_start and n < peak_end %}

          {% set is_weekend = now().weekday() >= 5 %}

          {% set tariff_2 = states('input_number.energy_usage_cost_tariff_2') | float %}
          {% set tariff_1 = states('input_number.energy_usage_cost_tariff_1') | float %}

          # Use tariff 2 in peak (excluding the weekend), else use tariff 1
          {{ tariff_2 if is_peak_hours and not is_weekend else tariff_1 }}
jmcollin78 commented 6 months ago

Yes it is a possibility. But Optimizing Solar consommation at night is not very useful I guess. What is the real use case behind this ?

stijnb1234 commented 6 months ago

Lol, didn't even think about that. I guess closed for now.