Skip to content

Instantly share code, notes, and snippets.

@NikolasK-source
Last active February 16, 2024 11:44
Show Gist options
  • Save NikolasK-source/84f07374d6d56d10b60656c1e883737a to your computer and use it in GitHub Desktop.
Save NikolasK-source/84f07374d6d56d10b60656c1e883737a to your computer and use it in GitHub Desktop.
Senec Home V2.1 1ph / Lithium json request
#!/bin/bash
#
# Copyright (C) 2022 Nikolas Koesling <[email protected]>.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# This script requests the following data from a senec battery of the type "Senec Home V2.1 1ph / Lithium" as json:
# - Mains frequency (PM1OBJ1 -> FREQ)
# - Mains voltage (3 phase) (PM1OBJ1 -> U_AC)
# - Mains current (3 phase) (PM1OBJ1 -> I_AC)
# - Mains total power (PM1OBJ1 -> P_TOTAL)
# - Battery charge (ENERGY -> GUI_BAT_DATA_FUEL_CHARGE)
# - Battery power (ENERGY -> GUI_BAT_DATA_POWER)
# - Battery voltage (ENERGY -> GUI_BAT_DATA_VOLTAGE)
# - Solar inverter power (ENERGY -> GUI_INVERTER_POWER)
# - Building electricity consumption (ENERGY -> GUI_HOUSE_POW)
# - Battery energy (ENERGY -> GUI_BAT_DATA_OA_CHARGING)
#check if command line argument exists
if [ ! $# -eq 1 ];
then
>&2 echo "invalid arguments!"
echo "usage: $0 IP"
echo " IP: IP address of the senec battery"
exit 1
fi
IP="$1"
curl https://$IP/lala.cgi --insecure -s -H 'Content-Type: application/json' -d '{"PM1OBJ1":{"FREQ":"","U_AC":"","I_AC":"","P_TOTAL":""},"ENERGY":{"GUI_BAT_DATA_FUEL_CHARGE":"","GUI_BAT_DATA_POWER":"","GUI_BAT_DATA_VOLTAGE":"","GUI_INVERTER_POWER":"","GUI_HOUSE_POW":"","GUI_BAT_DATA_OA_CHARGING":""}}'
@NikolasK-source
Copy link
Author

NikolasK-source commented Dec 7, 2022

It is a float value.
If you convert it as float the value is 283.106...

@amedeodivito
Copy link

Hello
i knew it was a float number, i didn't know how to convert it from c language.
I solved it like this:
long lo = strtol(hexstring, NULL, 16);
float fl = *(float *)&lo; // cast the address of the long as a float pointer and dereference.
Thanks again for your quick response
a greeting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment