Charge HQ Push API: JSON POST

I need some assistant to set this up as I’m not entirely clear how to do this or how it works.

Background:

Charge HQ is a web based service which automatically and remotely controls EV charge stations.

It polls data from solar PV inverters (or their web services) along with other available home energy parameters, and depending on how the ChargeHQ service is configured by the user it manages the charging of the car accordingly - ramping up and down the charge rate, turning the charger on and off etc.

In my case it is set to use excess solar PV only (unless I manually override that) and to avoid importing energy from the grid. Some leakage from the grid is inevitable/acceptable but one can set some thresholds to minimise this.

At present it polls data from our solar PV inverter’s online service, Fronius Solarweb, and while it works OK it has two main flaws:

  • it’s infrequent (updates every 1-2 minutes)
  • it’s using a snapshot of power values at that moment, rather than a filtered value such as a rolling average power over the past minute or so. IOW if a cloud floats overhead right when it polls, then it thinks our excess solar has been killed when really it’s just a transient event.

As a result, the way it adjusts charging can be suboptimal and cause issues with my other load management automations, in particular the charging of our home battery.

Accordingly I want to improve the performance of the service by sending it relevant filtered data directly and more frequently.

Proposed solution:

Charge HQ has a Push API which users are free to use.

There is one suggested for use with Home Assistant:

Assistance needed:

I’ve been trying to understand how to use this yaml code.

I understand I need to substitute in my API Key, and all the relevant sensors for the default placeholders.

My questions are:

  1. Where would this yaml go?
    configurations.yaml?

  2. Do I need to run an automation, or does this just run itself, performing a POST to the Charge HQ website every 30 seconds?

I don’t really understand how/why this is a binary sensor.

My understand of such things is rudimentary so any help is appreciated.
Many thanks.

I note this is similar to a code solution posted in this other thread.

1 Like

After getting a tip from elsewhere, I managed to get this working today so thought I would at least post the answers to my own questions in case someone else is wondering the same thing.

Firstly, the configuration code needed to be in a different format than the code shown above from the GitHub link, as follows:

command_line:
  - binary_sensor:
     name: ChargeHQ Stats
     command: >
      curl -X POST -H 'Content-Type:application/json' -d '{ "apiKey":"your-ChargeHQ-key-goes-here","siteMeters":{"consumption_kw":{{states('sensor.power_consumption')|float(0)/1000}},"net_import_kw":{{states('sensor.power_net')|float(0)/1000}},"production_kw":{{states('sensor.power_production')|float(0)/1000}}} }' https://api.chargehq.net/api/public/push-solar-data
     scan_interval: 30

As to my two questions:

  1. The code is pasted into the configuration.yaml file.

  2. It self runs, no need for any automations. HA does need to be restarted after the code change.

For the three input sensors I am using the ones provided by the Fronius SolarNet integration:

The SolarNet integration updates these at 10-second intervals, which means the API data sent to ChargeHQ every 30-seconds is using data no older than from 10-seconds prior.

However I needed to make an adjustment to the Consumption sensor - it needed it’s sign changed for the numbers to conform to the ChargeHQ API data format:

consumption_kw = production_kw + net_import_kw [ + battery_discharge_kw ]

In my case the consumption value was negative when it needed to been positive, and vice versa. So in the yaml code I changed the sensor configuration from:

{{states('sensor.power_consumption')|float(0)/1000}}

to

{{states('sensor.power_consumption')|float(0)/-1000}}

and the data tallies correctly at ChargeHQ’s end.

It’s working now and my charging current adjustments are now much more responsive than they were with the standard Fronius Solarweb connection.

Thanks for sharing this information. I’v just bought an EV (Kia ev6), and have solar, and am in the process of purchasing a charger, and contemplating a home battery. Also using Amber electricity as a provider.
I’ve been trying to figure out if there is a way I can have Home Assistant manage the charging such that I charge via solar when there is excess solar, unless the current purchase rate from Amber is lower than than solar feed in tariff. If I can figure that out, the next step is to try to work out rules around prioritising charging of car vs home battery.