gndean / home-assistant-hypervolt-charger

Home Assistant integration for Hypervolt EV charger
46 stars 3 forks source link

[Request] Expose set_schedule as a service #14

Closed itsjxck closed 1 year ago

itsjxck commented 1 year ago

Would it be possible to expose the set_schedule function from the API Client as a direct use service? I'm not overly concerned with tracking and managing the schedule itself within HA directly, as highlighted by your DateTime limitation, but in the meantime being able to make use of this to directly set the schedule by supplying a list of start/stop times would be immensely helpful.

My use case where this would be great:

I would attempt to do this myself and PR for you, but honestly I'm out of my depth with your python code (I'm a JS guy). That being said I am always keen to learn and give things a try, so if you want to contact me and watch me struggle while I ask you silly questions, my Discord is on my profile.

BadgerLoaf commented 1 year ago

As a stop gap, I wonder if the following could help you?

What about if you set an automation that sets the Hypervolt Mode to Super Eco when the price is 12p or higher, and one that sets it to Boost when it is below 12p ?

This would then only charge the car when the price is sub-12p (which I think is your aim?).

Incase you aren't aware, Super Eco means that the charger will only use excess Solar that would otherwise go to the grid charge the car - it doesn't mater if you don't have solar, it just means it will never be able to use it.. the same as at night or a cloudy day.

I do something effectvely the same where I am on Octopus Intelligent, and put the HV into Super Eco mode (i.e. Solar only) when I'm on peak price, allowing the cars to charge from any excess solar but not use any mains elec during peak prices.

Anyhow... just a thought incase it helped!

itsjxck commented 1 year ago

Oh interesting, thank you @BadgerLoaf! I did not know that, but I will investigate; this will probably work fine for me, as my template sensors state updates every half hour with the current period price, I'll just use that as a trigger.

BadgerLoaf commented 1 year ago

I'm def not expert, so maybe this isn't the right way to do it. But I just have the trigger set to detecting when the sensor changes ("the sensor" being a binary sensor that that I have setup for the on-peak / off-peak status)

So for me it changes as soon as it detects that change.

I'm pretty sure you could just set a trigger that activates when HA detects the price drops below (or goes above) the 12p mark, rather than needing to check every 30mins or something. Should make it more reactive.

Edit: Sorry ignore me.. i misread your message in my haste! And you already basically said what I put above!

itsjxck commented 1 year ago

I did exactly what you said and coupled it with a dropdown helper to allow me to easily change the threshold at which the automation turns on/off the charger. Probably pretty dull for experts but here's the automation:

alias: Automatic charger config based on energy unit price
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.charge_mode
      - sensor.octopus_agile_tracker
    to: null
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: input_select.charge_mode
                state: Override
                alias: Charge mode is Override
              - condition: and
                alias: Charge mode is 12p or less and unit price is 12p or less
                conditions:
                  - condition: state
                    entity_id: input_select.charge_mode
                    state: 12p or less
                  - condition: numeric_state
                    entity_id: sensor.octopus_agile_tracker
                    below: 0.12000000000001
              - condition: and
                alias: Charge mode is Free and unit price is 0 or less
                conditions:
                  - condition: state
                    entity_id: input_select.charge_mode
                    state: Free
                  - condition: numeric_state
                    entity_id: sensor.octopus_agile_tracker
                    below: 1.e-9
              - condition: numeric_state
                entity_id: sensor.octopus_agile_tracker
                below: 0
                alias: Always charge when negative
        sequence:
          - device_id: 74f9ccae89e17dfdf7ccfe001954ae6f
            domain: select
            entity_id: select.hypervolt_charge_mode
            type: select_option
            option: Boost
    default:
      - device_id: 74f9ccae89e17dfdf7ccfe001954ae6f
        domain: select
        entity_id: select.hypervolt_charge_mode
        type: select_option
        option: Super Eco
mode: single
gndean commented 1 year ago

@itsjxck Are you happy with the workaround? Setting the schedule times is something I'd like to add in the future, but probably when there is better support from HA for it.

itsjxck commented 1 year ago

Yes definitely, it works for me until setting a schedule becomes available.