Sure. Just email at [email protected]
I’ll replace the credentials in my config file and let you know.
Did you get my email and did you have time to check it?
Pablo.
Just did a quick check and got values back from the sensors, but as the record numbers are different from mine, difficult to make sense of it. But values come back alright.
I’m going to do a quick mock-up using value pairs from reported back from your system to confirm what I get back is correct and will update you.
Hope to do it tomorrow Saturday.
It works ok on values less than 70 ish on values higher it changes what it is, amps a few minutes later same sensor is volts, etc…
Is there a way to retrieve the data by “formatted value” instead of ID?
Sure there is but I haven’t gotten into it yet. From time to time the parsing gets out of sync and indeed the values don’t match but they get back to normal after a few minutes.
Right now I have no plans to work on this but if I get around to it I’ll post whatever I find.
hi friends.my name is anuradha and i am implementing web services provided by victron energy . now i am facing problem in using api. that is i am not getting how to use access token generated in 2nd step and the error i am getting is { “error”:“Login required”,
“error_code”: “invalid_credentials” } . waiting for response.
Did you solve it?
Good Day Guys,
Im new to Hassio , I managed to get it running on a Pi and decided to get the Victron integration working, I followed the steps as per the post but I don’t get any result.
Please help.
(upload://9TiBdlt0LCkV3ar3H5Ypb5KvK8z.png)
error warning
I have written a script to make this work for the problem of the changes in id numbers.
Right now I execute this every boot, as we are modifying sensors.yaml and has to be rebooted to make the changes appear on lovelace.
You can modify it and make it look for different values.
#!/usr/bin/env bash
id=$(curl -H "X-Authorization: Token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "https://vrmapi.victronenergy.com/v2/installations/XXXXX/diagnostics?count=1000" | jq '.records[] | select(.description=="Voltage")' | jq .id | head -n 1)
echo "The id is: $id"
echo "We are going to susbtract 1 because the array starts with 0: $x "
echo "I think, but maybe we have to subtract 2 ???"
x=$((id-1))
sed -ibackup -e "/^ battery/,/value/ s/\[[0-9][0-9]\]/[$x]/1" sensors.yaml
Hi. On the road today so will take a closer look later, but I can already see you have a typo in x-authorization field.
Can you correct it and try again?
I also found a way to parse the json response for the VRM variables I want to display rather than by position number, which solves the problem of having to change it when Victor adapts it’s API.
I’ll post it later.
No typo that I can see, script still works But you are welcome to improve it.
Still really curious about your method about getting the VRM variables.
Please share
The typo thing was for Denzel, not for you. Sorry
This is the way I’m doing it. Probably not the most elegant or efficient, but it works. I don’t know python so I’m doing it all using templating in HA yaml.
First, the API call
# Victron call for current installation data
- platform: rest
name: vrm data
json_attributes:
- success
- records
- num_records
resource: https://vrmapi.victronenergy.com/v2/installations/10986/diagnostics?count=1000
headers:
X-Authorization: Token mytoken
value_template: '{{ value_json.records[0].timestamp }}'
Then the parsing in a set of convoluted for and if loops.
I first loop through the “device”. 258 for the battery monitor, 256 for the MPPT charge, etc. using Victron’s own device numbering.
Second I look for the target string in the “description” field of the JSON output.
I run these loops for every sensor and sensor value I want to capture.
Important to check the formatting as the API output sometimes comes with units, and other times no units, etc.
Here is the example for Voltage and Current from the BMV (battery monitor).
battery_voltage:
friendly_name: 'Battery Voltage'
unit_of_measurement: 'V'
value_template: '{%- set object = "formattedValue" -%}
{%- set vrm_records = states.sensor.vrm_data.attributes.records -%}
{%- for device in ["258"] -%}
{%- for target in ["Voltage"] -%}
{%- for record in vrm_records -%}
{%- for key, value in record.items() -%}
{%- if value|string() == target|string() -%}
{%- for key, value in record.items() -%}
{%- if value|string() == device|string() -%}
{%- for key , value in record.items() -%}
{%- if key|string() == object|string() -%}
{{ value [:-2] | float() }}
{% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}'
battery_current:
friendly_name: 'Battery Current'
unit_of_measurement: 'A'
value_template: '{%- set object = "formattedValue" -%}
{%- set vrm_records = states.sensor.vrm_data.attributes.records -%}
{%- for device in ["258"] -%}
{%- for target in ["Current"] -%}
{%- for record in vrm_records -%}
{%- for key, value in record.items() -%}
{%- if value|string() == target|string() -%}
{%- for key, value in record.items() -%}
{%- if value|string() == device|string() -%}
{%- for key , value in record.items() -%}
{%- if key|string() == object|string() -%}
{{ value [:-2] | float() }}
{% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}'
And the result
Hey, it ain’t pretty (the code), but it works!
One day I’ll try to do it in python as an HA module…
Isgv, thanks for the original post, it was very informative and got me started.
My son has devised a slightly different way to extract the values by their code, rather than position. I have added an and to include instance as depending on your setup you may have more than one occurrence of the same code.
- platform: rest
name: vrm_data
json_attributes:
- success
- records
- num_records
resource: https://vrmapi.victronenergy.com/v2/installations/<siteID>/diagnostics?count=1000
headers:
X-Authorization: Token <your token here>
value_template: '{{ value_json.records[0].timestamp }}'
- platform: template
sensors:
battery:
friendly_name: 'Battery'
value_template: '{% for item in states.sensor.vrm_data.attributes.records if item["code"] == "SOC" and item["instance"] == 288 %}{{ item["formattedValue"][:-2] | float() | round(1) }}{% endfor %}' unit_of_measurement: '%'
Excellent! Thanks a lot, this seems much better and cleaner than what I had.
I had already taken into account the fact that the same value might occur more than once by looking for the device number. But as said, this code is much better.
I noticed that from time to time Victron implements breaking changes. For instance, up to a month or so ago, battery monitor battery value was “Battery voltage” and “Battery current”. But then those values stopped showing up on the front end. I checked using Postman and they had changed them to simply “Voltage” and “Current”. Easily fixed but I keep an eye for these changes.
Thanks for your contribution.
Hello Luis, I have managed to obtain information from the Api through the temporary token, but I have tried to follow the last part of your tutorial with the permanent token and it returns an error
{
“success”: false,
“errors”: “Access denied for this object”,
“error_code”: null
}
I’ve been reviewing everything for a while and I can not find the error
Could you help me, please?
Hi.
I can recreate the error message (403) you show by making an error in the installation number which I obviously cannot access.
An error with the token is type 401 Unauthorized.
So please check you are using the correct installation number and retry?
I’m using my idUser as an identifier, is that correct?
If I use the idSite it does not work either, I get this
{
“success”: false,
“errors”: “Path not found.”,
“error_code”: null
}