Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newbie Question - How to implement in HA #92

Open
plug-it-in opened this issue Oct 9, 2024 · 1 comment
Open

Newbie Question - How to implement in HA #92

plug-it-in opened this issue Oct 9, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@plug-it-in
Copy link

plug-it-in commented Oct 9, 2024

I really appreciate the work you've done to supply this. Unfortunately, as a real newbie to HA I am finding it all extremely difficult finding how to actually implement features.
So I installed via HACS download went well and it shows in HACS list of Service.

But what do I do now. Adding that service to a dashboard does nothing. I know you say configure in configuration YAML and happy to do this if I knew how to refer to the device I dont get the link between the configuration.yaml and the service.

This seems to be a common problem I encounter as do others. We get instructions how to install but no clues on implementation.

I put your example in configuration.yaml and it messed up all my existing Utility Meters. I presume I should have put it in a configurations.yaml file that does not exist on my system

The other completley baffling thing is in all your code its does not show how the two tariff rates are specified. I see the singe entry for price = 0.20 and thats it. How do you get offpeak and peak rates.

Ive been looking again and there is this sensor called sensor.current_energy_price but there is no code for this to set it up.

@zeronounours zeronounours added the help wanted Extra attention is needed label Dec 8, 2024
@zeronounours
Copy link
Owner

hello, indeed, we do not provide a way to set peak/offpeak rate as it is something external to this component.

The way to implement it highly depends on each case, for instance:

  • is the rate similar each day?
  • is the offpeak/peak rate changing at the same time each day?

You may need specific components to retrieve it directly from the electricity provider. If your rate change at fixed time and is the same every day, you can use the following configuration (still to be created in configuration.yaml):

input_number:
  peak_energy_price:
    name: Energy price during peak hours (cts/kWh)
    min: 0
    step: 0.01
    max: 30
    unit_of_measurement: EUX/kWh
    icon: mdi:currency-eur
  
  offpeak_energy_price:
    name: Energy price during off-peak hours (cts/kWh)
    min: 0
    step: 0.01
    max: 30
    unit_of_measurement: EUX/kWh
    icon: mdi:currency-eur

input_datetime:
  elec_peak_hours:
    name: Start of peak hours
    has_date: false
    has_time: true
  
  elec_offpeak_hours:
    name: Start of off-peak hours
    has_date: false
    has_time: true

template:
  - sensor:
      unique_id: real_peak_energy_price
      name: Peak energy price  (real value €/kWh)
      unit_of_measurement: EUR/kWh
      state: "{{ states('input_number.peak_energy_price') | float(0) / 100 }}"
  
  - sensor:
      unique_id: real_offpeak_energy_price
      name: Offpeak energy price (real value €/kWh)
      unit_of_measurement: EUR/kWh
      state: "{{ states('input_number.offpeak_energy_price') | float(0) / 100 }}"
  
  - sensor:
      unique_id: real_energy_price
      name: Energy price
      unit_of_measurement: EUR/kWh
      state: >
        {% set time = now().strftime('%H:%M:%S') %}
        {% set is_peak = time >= states('input_datetime.elec_peak_hours') and time < states('input_datetime.elec_offpeak_hours') %}
  
        {% if is_peak %}
        {{ states('sensor.peak_energy_price_real_value_eur_kwh') }}
        {% else %}
        {{ states('sensor.offpeak_energy_price_real_value_eur_kwh') }}
        {% endif %}

What this configuration do is:

  • create 2 number helpers: input_number.peak_energy_price and input_number.offpeak_energy_price which are the price in cents of the electricity during peak and off-peak hours. You can add them to your dashboard to change their values.
  • create 2 datetime helpers: input_datetime.elec_peak_hours and input_datetime.elec_peak_hours which are the beginning hours of each tariff periods. You can also add them to your dashboard.
  • create 3 template sensors:
    • sensor. sensor.peak_energy_price_real_value_eur_kwh which is the price in euro (of course you can change for any other crrency) of your energy during peak.
    • sensor. sensor.offpeak_energy_price_real_value_eur_kwh which is the price in euro of your energy during off-peak.
    • sensor. sensor.energy_price which is your current energy price. This is the one you want. It will change automatically based on your selected peak/off-peak hours and the price for each period.

Important note: this configuration only works if your peak hours start before your offpeak. For instance, peak start at 5AM and offpeak starts at 9PM. But it won't work if offpeak starts at 1AM and peak at 8AM.

Does it help you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants