Last active
August 23, 2022 18:05
-
-
Save danielolsson100/5003bffe864781dfc86269978233eac4 to your computer and use it in GitHub Desktop.
cookie based ferroamp cloudAPI request for Home Assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- id: '1657117435589' | |
alias: Set Export Threshold | |
description: '' | |
trigger: | |
- platform: state | |
entity_id: | |
- input_number.export_threshold | |
condition: [] | |
action: | |
- service: shell_command.set_export_threshold | |
data: {} | |
mode: single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input_number: | |
export_threshold: | |
min: -11000 | |
max: 0 | |
step: 1000 | |
mode: slider | |
unit_of_measurement: "W" | |
icon: mdi:solar-power | |
sensor: | |
- platform: command_line | |
name: ferroamp_cloudapi_grid_export_threshold | |
command: |- | |
loginform='{"email":"[email protected]","password":"YourPasswordHere"}'; | |
baseurl='https://portal.ferroamp.com'; | |
id=enter facility ID ie ABCD | |
cookie=$(curl -H 'Content-Type: application/json' -d $loginform -ksc - $baseurl/login -o /dev/null); | |
echo "${cookie}" | curl -ksb - $baseurl/service/ems-config/v1/current/$id | |
value_template: |- | |
{% set json = value_json %} | |
{{json.emsConfig.data.grid.thresholds.low}} | |
scan_interval: 3600 | |
unit_of_measurement: 'W' | |
shell_command: | |
set_export_threshold: bash /config/shell/ferroamp_cloudapi.sh {{ states('input_number.export_threshold') | round (0) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist is for ferroamp energy system with integration to Home Assistant to add the option to control "Export Threshold" dynamically | |
the API is not supported by ferroamp so use it at your own risk!! and it's written for PoC purposes for #Geeks :) | |
By Daniel Olsson | |
This scripts below needs to be updated with email / password and facility ID to work. | |
1. Create a shell script on the Home Assistant server at /config/shell/ferroamp_cloudapi.sh | |
3. Modify configuration.yaml to add command_line module / input_number / shell_command. | |
4. Add automation to map any change to the input_number to trigger a change in the portal as the examle in automations.yaml | |
5. Reboot Home Assistant and give it a try by changing export_threshold manually of with an automation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Shell script for Home Assistant with ferroamp energyhub to update Export Threshold without GUI by Daniel Olsson | |
# Disclamer: Totally unsupported by ferroamp support - use at own risk. | |
if [ -n "$1" ]; then | |
# create session cookie and get current running parameters | |
loginform='{"email":"[email protected]","password":"YourPasswordHere"}'; | |
baseurl='https://portal.ferroamp.com'; | |
id=enter facility ID ie ABCD | |
cookie=$(curl -H 'Content-Type: application/json' -d $loginform -ksc - $baseurl/login -o /dev/null); | |
response=$(echo "${cookie}" | curl -ksb - $baseurl/service/ems-config/v1/current/$id) | |
else | |
echo "Export Threshold parameter not supplied. It must be in range between -11000 to 0" | |
exit 0 | |
fi | |
# Modify responsedata and remove header and validate data between -11000 and 0 | |
export_threshold=$1 | |
if ((export_threshold <= 0 && export_threshold >= -11000)); then | |
body_tmp=$(echo $response | jq ".emsConfig.data.grid.thresholds.low = $export_threshold" | jq '.emsConfig' | jq 'del(.header)') | |
else | |
echo "Export Threshold value is not in range between -11000 and 0" | |
exit 0 | |
fi | |
# create correct body to post, replace data with payload and create compressed string as body output | |
body=$(echo ${body_tmp/"data"/"payload"} | jq -c) | |
# Update portal with new POST data | |
response=$(echo "${cookie}" | curl -ksb - $baseurl/service/ems-config/v1/commands/set/$id -d $body -H "Content-Type: application/json") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment