CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
141 stars 31 forks source link

Boost Service #383

Open SciFi-Bob opened 1 year ago

SciFi-Bob commented 1 year ago

Hi there,

I am sure that this is a shortcoming of mine rather than your code but I can't get the boost service to work. I choose my Zappi and set a boost amount. The Dev tools service call gives me a green tick but nothing actually happens.

Any advice on trouble shooting would be greatly appreciated.

Shellwood commented 1 year ago

Hi SciFi-Bob,

Any joy here? i tried somethign similar with the Boost service for the Eddi, and noting happened.

Many thanks

SciFi-Bob commented 1 year ago

No, nothing unfortunately. I really want to dump any excess battery into the car before the overnight grid charge so this is a shame

Shellwood commented 1 year ago

Yes. I am hoping to dump excess remainng charge in the home battery into the hot water tank at 6am before the boiler kicks-in to get the hot water to shower temperature.

Will post back here if my tinkering has any joy.

Rich1887 commented 1 year ago

I have a button on my dashboard to start a boost for 15 minutes on the EDDI. I'm no programmer, I fumble through Youtube videos to try get things working. I used this video, https://www.youtube.com/watch?v=sNmonuw4EHo&t=237s to combine the custom button-card and a helper and automation to get it working. I did it some while back so cannot remember how and would have to watch the video again to remember! I have a helper I named Boost Immersion 15 Minutes, it has icon mdi:power and entity input_boolean.boost_immersion_15_mins I installed the Custom Button-Card from HACS. This is the Button-Card config

type: custom:button-card entity: input_boolean.boost_immersion_15_mins show_state: true name: Boost Immersion 15 mins styles: card:

I have an Automation, called boost eddi 15 mins The trigger is When Boost Immersion 15 mins changes from Off to ON

platform: state entity_id:

The action is Call a Service 'myenergi:boost'and have Heater 1 and 15 minutes configured in the service.

service: myenergi.myenergi_eddi_boost data: target: Heater 1 time: 15 target: area_id: hot_press device_id: 08b2ce48867976c92f432b793ea3e805

Then I have set a delay for 15 minutes and then to get the button to turn grey I call service 'input_boolean:turn off'

service: input_boolean.turn_off data: {} target: entity_id: input_boolean.boost_immersion_15_mins

I hope that makes sense and is of some help.

What I havn't been able to do is to make a button that will cancel the boost, I don't think there is a service in the myenergi integration to call the Stop All function, so if ineed to stop it before the scheduled time is up I just use the app on my phone to stop it boosting.

LeiChat commented 1 year ago

Thanks for sharing. To stop the boost you could change the select.myenergi_eddi_XXX_operating_mode entity from Normal to Stopped.

Shellwood commented 1 year ago

Thanks Rich1887 - my error was not selecting a target device in the automation. i was calling the service, and had the "target" as "heater 1" and a time set, but also needed to select "eddi-xxx", as teh device in "targets".

Yaml for the relecant part of the automation now looks like:

service: myenergi.myenergi_eddi_boost data: target: Heater 1 time: 1 target: device_id: 1fcb41b7da0ce64567e776334ec0d736 .... where this is teh unique device ID of teh eddi

Thanks for your help!

Rich1887 commented 1 year ago

having leached on the HA community for years, it's nice to give a tiny bit back.

ando2040 commented 8 months ago

Thanks @Rich1887 that was very helpful as a proof of concept. In my case it's a Zappi target and my intention is to build my own version of smart charging, so that I can switch to Octopus Agile tariff and use optimal price periods. This is working for my immersion heater already (a much simpler on/off Tuya switch) using the code here: https://community.home-assistant.io/t/octopus-agile-display-tariff-in-graphs-tables-best-import-export-periods-all-done-using-node-red-and-jsonata/518762

I'm glad it's not just me who couldn't find "Service to stop boost" which is specifically mentioned on the CJNE README. That's not a criticism - this is an awesome integration that creates something that MyEnergi have not. However it's curious. Setting the whole system to "stopped" is possible, as is using Smart Boost - I think it will be possible to programmatically set the stop time when you set up the boost. But both are a little kludgey. I'll post again when I've settled on a solution.

kosi2801 commented 8 months ago

@SciFi-Bob I had trouble initially getting the Boost Service to do anything at all initially too. What I realized eventually is that when calling the service you don't specify "how many kWh to add" in the "amount" variable but rather a "boost until this 'kWh added in this session'".

So if you eg. already charged 4 kWh since your car was plugged in (ie. the charge-session started for Zappi) and you wanted to charge 4 additional kWh, then you have to call the boost-service with an amout of "8".

(On my Zappi anything lower than the current session-charged amount resulted in a 1ph-charge of the lowest charge-current for ~1min and then the Zappi stopped the charging with an error.)

Maybe this could be also the case in your scenario?

SciFi-Bob commented 8 months ago

Thanks for that clarification, so the action needs to be current + desired, sure I can manage that math 🙂

Regards

Phil Williams

M: 07867 977671<tel:07867%20977671> E: @.**@.>


From: kosi2801 @.> Sent: 04 January 2024 12:31 To: CJNE/ha-myenergi @.> Cc: Phil Williams @.>; Mention @.> Subject: Re: [CJNE/ha-myenergi] Boost Service (Issue #383)

@SciFi-Bobhttps://github.com/SciFi-Bob I had trouble initially getting the Boost Service to do anything at all initially too. What I realized eventually is that when calling the service you don't specify "how many kWh to add" in the "amount" variable but rather a "boost until this 'kWh added in this session'".

So if you eg. already charged 4 kWh since your car was plugged in (ie. the charge-session started for Zappi) and you wanted to charge 4 additional kWh, then you have to call the boost-service with an amout of "8".

On my Zappi anything lower than the current session-charged amount resulted in a 1ph-charge of the lowest charge-current for ~1min and then the Zappi stopped the charging with an error.

— Reply to this email directly, view it on GitHubhttps://github.com/CJNE/ha-myenergi/issues/383#issuecomment-1877022564, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOLFTA2C46E3NOR4KG33FTYM2OJHAVCNFSM6AAAAAAZSBFL26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXGAZDENJWGQ. You are receiving this because you were mentioned.Message ID: @.***>

kosi2801 commented 8 months ago

(@SciFi-Bob you should remove your phone number from the comment :-) )

For reference, the step in my YAML-script that starts a charge of up to 80% of the car (having a 50kWh batt) is as follows:

...
  - service: myenergi.myenergi_boost
    data:
      amount: >-
        {{            
            [
            ((80.0 - ( states('sensor.psa_battery_level') | float )) 
            / 2 )
            | round(0)
            , 1.0 ] | max
            + states('sensor.myenergi_zappi_xxxyyy_charge_added_session') | float(0)
        }}       
    target:
      device_id: xxxyyy
...

sensor.psa_battery_level is the current charge percentage of my car, sensor.myenergi_zappi_xxxyyy_charge_added_session of course the charge already put into the car in this whole session. /2 is there because 2% addl. = 1kWh charge, the round(0) is there to only send full integers to the service (it converts it internally anyway, but just to be sure here) and the max is to not send a +0 kWh charge to the Zappi which also may cause issues. I also do a check if the car is already at >=80% before this step so dealing with negative numbers is not an issue.

Probably that call can be further tweaked and some parts removed, but I didn't want to touch it anymore when it finally worked after days of investigation what's going on :-D

ando2040 commented 8 months ago

Thanks, that's also very helpful - I hadn't started to wrestle with this yet.

So for my car with a 77kWh battery, I calculate 1% as 0.77 and therefore the divisor to be 1/0.77 = 1.3, have I got that right?

I think I will create a slider helper to populate the desired % rather than hard-coding the 80% but this is another great proof of concept.

kosi2801 commented 8 months ago

@ando2040 Yes, 1.3 as divisor should be correct 👍

ando2040 commented 8 months ago

In fact I will probably just change the formula to *0.77 which would be a little more easy to read! Your 50kWh battery divides easily, most people's will not.

ando2040 commented 8 months ago

Here's my updated version of your automation. If there were a "stop all" boosts in the integration as there is in the MyEnergi app it would be easier but this works for me. I could also have used the sledgehammer of switching between "fast" and "stopped" modes but I liked your way. Not least because it allows me to use the car's app for the target state of charge.

I've added a switch into Eco+ mode because I was using Fast by default. Plus a delay because I had some.

I've included my (disabled) template to provide UK low-carbon charging (and optimal price if you're on Agile Octopus tariff) I'm planning to switch, but the code works (and reduces your EV's carbon intensity) before you are on the tariff because Octopus provide the rates on a public API. This has a tricky prereq, see comment - comments are allowed in Jinja code!

I decided to use the car's charge limit rather than hard-coding 80%. The home assistant integration for my EV provides this as a number entity, so I can use the car's app to set the target amount, and this automation will only start the charge when UK carbon intensity/wholesale price is lowest for that night.

I haven't thought of a way to avoid hard-coding the max charge kWh but I have switched it from a division to a multiplication - *0.75 is the best guess of a 75kWh max charge on my EV.

You'll need to provide your Zappi serial number in the xxxxxx, and the correct device ID of course

alias: Boost Zappi to Car Charge Limit (in Eco+ Mode)
description: Boost Zappi to Car Charge Limit (in Eco+ Mode)
trigger:
  - platform: template
    id: "on"
    value_template: >
      {% set ns=namespace() %} //Enable this template for UK low carbon
      charging, or optimal price if you're on Agile Octopus tariff

      {% set ns.flag=false %} //Install the (tricky) prereqs from
      https://community.home-assistant.io/t/octopus-agile-display-tariff-in-graphs-tables-best-import-export-periods-all-done-using-node-red-and-jsonata/518762

      {% for event in state_attr('sensor.octopus_agile_sequence_table_2',
      'import_array')%}
        {% set ontime=(as_timestamp(event.from)|int-as_timestamp(now())|int) %}
        {% set ns.flag = ns.flag or ( 0 < ontime < 120) %}
      {% endfor %}

      {{ns.flag}} 
    enabled: false
  - platform: state
    entity_id:
      - input_boolean.boost_zappi
    from: "off"
    to: "on"
condition: []
action:
  - service: select.select_option
    metadata: {}
    data:
      option: Eco+
    target:
      entity_id: select.myenergi_zappi_xxxxxxx_charge_mode
  - delay: "00:01:00"
  - service: myenergi.myenergi_boost
    data:
      amount: |-

        {{ 
            [
            ( ( ( states ('number.charge_limit') | float ) - ( states('sensor.battery') | float ) ) 
            * 0.75 ) 
            | round(0)
            , 1.0 ] | max
            + states('sensor.myenergi_zappi_xxxxxxx_charge_added_session') | float(0)
        }}  
    target:
      device_id: 40061624ae5856a2c3442b6b1c4ab5
mode: single