Skip to content

Instantly share code, notes, and snippets.

@danielolsson100
Last active April 13, 2023 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielolsson100/1c99bae4e2605540854a73b1e13a6309 to your computer and use it in GitHub Desktop.
Save danielolsson100/1c99bae4e2605540854a73b1e13a6309 to your computer and use it in GitHub Desktop.
ferroamp Read and set Import threshold from HA
- id: '1665917079136'
alias: Ferroamp - Set Import threshold = -1000
description: ''
trigger: []
condition: []
action:
- service: shell_command.set_import_threshold
data:
threshold: -1000
mode: single
sensor:
- platform: command_line
name: ferroamp_cloudapi_grid_import_threshold
command: |-
loginform='{"email":"a@b.c","password":"YourPasswordHere"}';
baseurl='https://portal.ferroamp.com';
id=enter facility ID number ie 1234
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.high}}
scan_interval: 3610
unit_of_measurement: 'W'
shell_command:
set_import_threshold: bash /config/shell/ferroamp_cloudapi_import.sh {{ threshold }}
#!/bin/bash
# Shell script for Home Assistant with ferroamp energyhub to update Import 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":"a@b.c","password":"YourPasswordHere"}';
baseurl='https://portal.ferroamp.com';
id=enter facility ID number ie 1234
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 "Import Threshold parameter not supplied. It must be in range between -11000 to 11000"
exit 0
fi
# Modify responsedata and remove header and validate data between -11000 and 11000
import_threshold=$1
if ((import_threshold <= 11000 && import_threshold >= -11000)); then
body_tmp=$(echo $response | jq ".emsConfig.data.grid.thresholds.high = $import_threshold" | jq '.emsConfig' | jq 'del(.header)')
else
echo "Import Threshold value is not in range between -11000 and 11000"
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 - https://portal.ferroamp.com/service/ems-config/v1/commands/set/$id
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