Nested JSON in Homey Script - working on Volt Time Cloud Charger script

Maybe someone is able to help here.
I’m busy creating a Homey Script that serves to read all data from a Volt Time Source 2 EV charger and exposes all this data to later control the charger via other scripts - and to use it in advanced flow logic. I’m quite far already, but this is the problem I run into;
I’m using the data provided by Volt Time Cloud itself in the API docs - so I don’t expose any personal information;

Consider this response structure:

{
  "data": {
      "id": 596411,
      "identity": "VTT_0001",
      "connection_status": "offline",
      "status": "Available",
      "error": "NoError",
      "error_info": null,
      "created_at": "2023-11-01T09:17:10.000000Z",
      "updated_at": "2023-11-02T14:15:11.000000Z",
      "connectors": [
          {
              "id": 1655489,
              "charger_id": 596411,
              "connector_id": 1,
              "status": "Available",
              "error": "NoError",
              "error_info": null,
              "created_at": "2023-11-01T09:44:32.000000Z",
              "updated_at": "2023-11-01T10:15:36.000000Z"
          }
      ]
  }
}

I’m able to directly read any direct child by (after storing it in the variable ‘body’) adressing it as:

await tag (‘status’ , body.data[0].status); - this returns me the status exactly.

However; this does not work for the nested ‘connectors’ . and this is where it gets specific and weird;
I do get the expected data in postman - including the connectors child data.

If I however log the exact data homey is using from the query - it summarizes the child with
[ [Object] ]
, so I get;

{
“data”: {
“id”: 596411,
“identity”: “VTT_0001”,
“connection_status”: “offline”,
“status”: “Available”,
“error”: “NoError”,
“error_info”: null,
“created_at”: “2023-11-01T09:17:10.000000Z”,
“updated_at”: “2023-11-02T14:15:11.000000Z”,
“connectors”: [ [Object] ]
}
}

Now - obviously - even when using the correct syntax - I don’t get any data from the connectors child. instead it gives me: TypeError: Cannot read properties of undefined (reading ‘connectors’).

I’m not so knowledgeable that I have a strategy to work around this particular problem. Can someone point me in the right direction ? breaking up in a flow with response cards and additional logic and is - unless I can help it - not the way to go. I want the script to be as independent as can be.

Thanks in advance,

Vince

I don’t see how, because body.data should be an array for that to work, and your example is showing that body.data is an object.

I don’t know what you think the “correct syntax” is, but to access (say) the status of the first connector, the accessor is:

body.data.connectors[0].status

Robert, you know how sometimes when you are looping through repetitive work - you seem to miss the obvious ? Thanks for pointing out something I completely overlooked. My example of fetching the data was actually based upon earlier points in my script that did work. And almost every call in this API results in an array to begin with. So that is where my blind spot was - I missed the fact that data is not an array here - as opposed to every earlier resultset.
Thanks ! it’s working - expecting to finish this script soon and then I’ll be able to get all data from the charger - and control it too - via homeyscript.

1 Like

VoltTime Charger

  • first version of script is available

Hi @Vincent_Verbon and @robertklep,
As you’ve already invested time in connect the Volttime Cloud to Homey, I wonder what the status is. For me, creating a script or app is a bridge to far, I’m already happy I can create flows in Homey…

My case/challenge: I want to be able to switch an EV charger (in my case Ratio Io6) ‘on’ or ‘off’ by Homey. As Ratio doesn’t have a Homey app, they recommended using Volttime Cloud. I contacted them after I noticed the Homey logo on their website (Volt Time Cloud – Volt Time), but they confirmed they don’t have a Homey app (yet, they are looking for somebody able to make) and ‘programming’ is required (which I’m not able to, unfortunately).

When it’s possible to switch the charger on/off by Homey, I’m able to create a flow like:

  • When my Tesla is ‘at home’ (using data from the Tesla app)
    and
  • When I open the charging port of my Tesla
    then
  • My EV charger is switched on (and charging starts instantly after connected the cable; no need to use the Ratio brand app for that)

Background:
We have two Tesla’s, one ‘private’ and one ‘business’. For charging ‘private’ I want the described process applies. When charging ‘business’ a RFID card will be used to switch on the charger (and charging cost will be charged to my wife’s employer using the ‘backoffice’ service).

As we’ve two Tesla’s, we can use the Tesla app to manage the charging (level) and apply ‘load balancing’ and ‘solar charging’ in Homey flows. The charger will not manage (‘push’), but the cars will manage (‘pull’) the charging(level). That’s why we actually only need ‘something’ (code) to switch the EV charger ‘on’ and ‘off’ (using the Volttime cloud platform).

Hope you have a solution and thanks a lot in advance!

(it should be interesting when there is a Homey app in the future for Volttime Cloud, as that’s means there is a general solution to integrate all EV chargers in Homey flows; Volttime confirmed this is their ambition as well).

Hey Marcel.

There is a documented API call for VolttimeCloud to switch the connector on the EV in a disabled/enabled state:
see: Enable Connector - Volt Time Cloud and Disable Connector - Volt Time Cloud. In it’s simplest form you could simply make a script that just does this for you (one to enable, one to disable) and hard code the variables in your script. I would advise you to exclude the API key from hardcoding - and reference that by a variable (using better logic for instance). This mainly to protect yourself from unintentionally sharing your API key with others. However- for testing purposes you could do even that to test that your setup works.
You would then call the script from within your flow to either disable or enable your connector.

Now pertaining to your specific usecase: as far as my experience with EV chargers go (which is not saying a lot) - there is a difference between ‘switching on’ and ‘authenticating to’ your EV charger.
Disabling the connector actually really disables the connector. - the charging point is unavailable until you switch it on again. As for authenticating; your RFID card enables the authentication that starts your charging session on an already ‘enabled’ connector.

So enabling a connector that was switched off really doesn’t mean that something else happens for you in terms of identifying which car is actually being charged by which id. The VoltTime app lets me specify the default ID for charging and the setting to apply this to every session without presenting the card. But this would not work in your situation.

What you might actually be looking for then is a way to set the ID for the charging session by logic. For instance; opening your charging port of your tesla sets the ID for the next charging session to your private credentials and if the charging port of your wife’s tesla is opened - it sets the ID to the business credentials for the next charging session.

There is no way to set the credentials through the volttime cloud API as far as I’m aware.

So the question is really - does the ratio app actually enable/disable the connector or only enable/ start the session. Maybe if it really enables/disables the connector you could combine it with the mentioned call earlier and set the volttime cloud default account to your private credentials and set it to auto authenticate. Then test if it indeed behaves so that enabling the connector applies the default behaviour - and that enabling through ratio app overrides the default behaviour to apply the business credentials

Hi Vincent,

Thanks for your explanation.

About the first part (creating a script): for me this is like reading Chinese for me. I just installed Homey Script for the first time, as I assume I need. Studying the example scripts (Javascript?), I felt very stupid. Ok, trying my best, I could understand what is going on, but no way I can reproduce or create something like that myself.

The second part, about the charger, I understand better. I assumed holding a authentication card in front of the RFID in front of the charger both authenticates and enables the charger (loading just starts), but indeed, I have to check with Ratio.
If it doesn’t work that way, I think it becomes (far too) complex for me and I hope Homey and/or Volttime will make an app (for all Homey users without programming skills like me). I contacted both and both confirmed they are interested in creating an app. It should be great if one app that can control (OCPP) chargers from several/all brands (and all brand focused apps are no longer required). Unfortunately, both also confirmed they actually don’t have the resources to make that app shortly and I maybe just have to be patient.