Created
July 19, 2023 07:52
-
-
Save danielolsson100/b34e32b0ad1a8416a2e7b81c0b3efc77 to your computer and use it in GitHub Desktop.
Ferroamp cloudAPI for Home Assistant to get Sensor data and control export limit
This file contains hidden or 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: '1689579754727' | |
alias: Ferroamp - Set Limit Export | |
description: '' | |
trigger: | |
- platform: state | |
entity_id: | |
- input_boolean.limit_export | |
condition: [] | |
action: | |
- service: shell_command.set_limit_export | |
data: {} | |
mode: single | |
- id: '1657117435589' | |
alias: Ferroamp - 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 hidden or 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
- sensor: | |
name: ferroamp_cloudapi_data_grid | |
command: |- | |
loginform='{"email":"YOUR-E-MAIL","password":"YOUR-PASSWORD"}'; | |
baseurl='https://portal.ferroamp.com'; | |
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/YOUR-FERROAMP-ID | |
value_template: |- | |
{% set json = value_json %} | |
{{json.emsConfig.data.grid.ace.mode}}| | |
{{json.emsConfig.data.grid.ace.threshold}}| | |
{{json.emsConfig.data.grid.limitExport}}| | |
{{json.emsConfig.data.grid.limitImport}}| | |
{{json.emsConfig.data.grid.thresholds.high}}| | |
{{json.emsConfig.data.grid.thresholds.low}}| | |
{{json.emsConfig.data.battery.powerRef.charge}}| | |
{{json.emsConfig.data.battery.powerRef.discharge}}| | |
{{json.emsConfig.data.battery.socRef.high}}| | |
{{json.emsConfig.data.battery.socRef.low}}| | |
{{json.emsConfig.data.mode}}| | |
{{json.emsConfig.data.pv.mode}} | |
scan_interval: 3600 |
This file contains hidden or 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_boolean: | |
limit_export: | |
name: "Limit Ferroamp Export" | |
template: | |
sensor: | |
- name: FA Mode | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[10] | default }}" | |
icon: mdi:auto-mode | |
- name: FA Grid ACE Threshold | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[1] | default }}" | |
unit_of_measurement: A | |
device_class: current | |
- name: FA Grid Import Threshold | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[4] | default }}" | |
unit_of_measurement: W | |
icon: mdi:transmission-tower-import | |
device_class: power | |
- name: FA Grid Export Threshold | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[5] | default }}" | |
unit_of_measurement: W | |
icon: mdi:transmission-tower-export | |
device_class: power | |
- name: FA Battery PowerRef Discharge | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[7] | default }}" | |
unit_of_measurement: W | |
icon: mdi:battery-arrow-down | |
device_class: power | |
- name: FA Battery PowerRef Charge | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[6] | default }}" | |
unit_of_measurement: W | |
icon: mdi:battery-arrow-up | |
device_class: power | |
- name: FA Battery SoCRef Low | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[9] | default }}" | |
unit_of_measurement: '%' | |
device_class: power_factor | |
- name: FA Battery SoCRef high | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[8] | default }}" | |
unit_of_measurement: '%' | |
device_class: power_factor | |
binary_sensor: | |
- name: FA Grid ACE Mode | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[0] | default }}" | |
icon: mdi:share-variant | |
- name: FA PV Mode | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[11] | default }}" | |
icon: mdi:solar-power | |
- name: FA Grid Limit Import | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[3] | default }}" | |
icon: mdi:transmission-tower-import | |
- name: FA Grid Limit Export | |
state: "{{ states('sensor.ferroamp_cloudapi_data_grid').split('|\n')[2] | default }}" | |
icon: mdi:transmission-tower-export | |
shell_command: | |
set_limit_export: bash /config/shell/ferroamp_cloudapi_limit_export.sh {{ states('input_boolean.limit_export') | bool | lower }} |
This file contains hidden or 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 configure Limit Import setting without GUI by Daniel Olsson | |
# Disclamer: Totally unsupported by ferroamp support - use at own risk. | |
# Store the file on your HA below \\HA-IP\config\shell | |
if [ -n "$1" ]; then | |
# create session cookie and get current running parameters | |
loginform='{"email":"YOUR-E-MAIL","password":"YOUR-PASSWORD"}'; | |
baseurl='https://portal.ferroamp.com'; | |
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/YOUR-FERROAMP-ID) | |
else | |
echo "Limit Import parameter not supplied. It must be true or false" | |
exit 0 | |
fi | |
# Modify responsedata and remove header and validate data. | |
body_tmp=$(echo $response | jq ".emsConfig.data.grid.limitExport = $1" | jq '.emsConfig' | jq 'del(.header)') | |
# 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/958 | |
response=$(echo "${cookie}" | curl -ksb - $baseurl/service/ems-config/v1/commands/set/958 -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