CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
134 stars 28 forks source link

Add in an entity called "in session" which during a charge session is ON and when the session ends it changes to OFF #466

Open daknightuk opened 5 months ago

daknightuk commented 5 months ago

Is your feature request related to a problem? Please describe. My problem is that I want to get the KWH of the last charge session. The entity myenergi zappi-2488xxxx Charge added session shows only the session just ended.

Describe the solution you'd like I want something to trigger an automation when the session ends so that I can add the KWH to another entity which is a accumalative total.

Describe alternatives you've considered I can't see how I can do a trigger without a change in state

Additional context Current dashboard

image

I want to be able to add Car Charged Total in KWH

LeiChat commented 5 months ago

If you don't charge across midnight, could you use a Utility Helper that calculates the daily totals from the zappi's internal load CT1 entity?

daknightuk commented 5 months ago

@LeiChat I like this idea of using the utility helper my tariff is across midnight the thing that really confuses things is the way the tariff operates, you see I get 2 rates Night rate 23:30-05:30 (Cheap period) Day rate 05:50-23:30 (Expensive period) Also the Zappi is controlled by Octopus energy so sometimes they choose to charge my car during what would be the Day Rate and they only charge the Night Rate

LeiChat commented 5 months ago

I am using https://github.com/megakid/ha_octopus_intelligent for Octopus IO. There is another Octopus integration available through HACS that features more entities/functionality but this one serves my needs.

It includes a binary_sensor.octopus_intelligent_slot which returns true during your default off-peak hours and when Octopus have created a slot for your zappi to boost.

Perhaps there's a way (Template?) to combine something like the Utility Helper and the boolean state of that sensor to generate daily consumption (and cost).

daknightuk commented 5 months ago

I tried the utility meter sensor.myenergi_zappi_2488xxxx_power_ct_internal_load which gave me 7.1kwh, but utility meter went crazy, now I notice when I log into the myenergi website and go to energy use \ charging sessions it says at the top image Is there any way to pull that value into HA?

plord12 commented 5 months ago

This is what I use for notifications to my phone :

alias: Car - Charging notification
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.myenergi_zappi_20885812_status
    for:
      hours: 0
      minutes: 0
      seconds: 5
    not_from: unavailable
    not_to: unavailable
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.myenergi_zappi_20885812_status
        state: Charging
action:
  - service: script.info
    data:
      message: >
        {% if is_state('sensor.myenergi_zappi_20885812_status', 'Charging') %}  

        Car charging started 

        {% elif is_state('sensor.myenergi_zappi_20885812_status', 'Boosting')
        %}  

        Car charging started (Boosting)

        {% elif is_state('sensor.myenergi_zappi_20885812_status', 'Paused') %}  

        Car charging paused - {{
        states('sensor.myenergi_zappi_20885812_charge_added_session',
        with_unit=True) }} added

        {% elif is_state('sensor.myenergi_zappi_20885812_status', 'Completed')
        %} 

        Car charging completed - {{
        states('sensor.myenergi_zappi_20885812_charge_added_session',
        with_unit=True) }} added  

        {% else %} 

        Car charging state changed - status {{
        states('sensor.myenergi_zappi_20885812_status') }}

        {% endif %}
mode: single
MaximumFish commented 3 months ago

I've actually just done this myself. I setup a ulility meter helper using the entity myenergi zappi-xxxxxxxx Energy used today (because this entity appears to account for the total energy used for a charge - including losses), checking the options "Periodically resetting" and "Sensor always available".

For the automation that toggles between peak and off-peak I use both time triggers and the Octopus Energy HACS integration to detect rate changes going above or below 10p/kWh (just to keep it simple and account for future price hikes), though the one LeiChat mentions would also work, which it looks like you're already running? Anyway, the automation looks like this:

alias: "Octopus: Tariff rate change"
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.octopus_energy_electricity_xxx_xxx_current_rate
    above: 0.1
    id: peak
  - platform: time
    at: "05:30:00"
    id: peak
  - platform: numeric_state
    entity_id:
      - sensor.octopus_energy_electricity_xxx_xxx_current_rate
    below: 0.1
    id: off-peak
  - platform: time
    at: "23:30:00"
    id: off-peak
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - peak
        sequence:
          - service: select.select_option
            target:
              entity_id:
                - select.car_charge_meter
                - select.octopus_energy_meter
            data:
              option: peak
      - conditions:
          - condition: trigger
            id:
              - off-peak
        sequence:
          - service: select.select_option
            target:
              entity_id:
                - select.car_charge_meter
                - select.octopus_energy_meter
            data:
              option: off-peak
mode: single

I haven't got around to doing costings yet so you're ahead of me there! Really I just wanted it so that I could separate car charges from general home energy usage when the bill comes in, though I like what you've done with your dashboard.