safepay / sensor.fronius

A Fronius Sensor for Home Assistant
MIT License
80 stars 31 forks source link

Add 'battery_usage' sensor to powerflow #78

Open lochstar opened 2 years ago

lochstar commented 2 years ago

Closes #66

I've added the config values battery and battery_device_id.

battery_usage is included as P_Akku via GetPowerFlowRealtimeData.fcgi.

The following sensors are provided by GetStorageRealtimeData.cgi.

battery_designed_capacity
battery_maximum_capacity
battery_charge
battery_temperature
battery_current
battery_voltage

I'd also like to include battery_manufacturer, battery_model and battery_serial, the JSON response has these values nested under Details (see below). Currently the json_key attribute doesn't support a keypath. I wasn't sure how to handle this, either an extra json_sub_key attribute or add a library such as python-benedict that supports keypaths. Unsure if HA provides something similar already. Thoughts?

Sample response of GetStorageRealtimeData:

{

    "Body": {
        "Data": {
            "Controller": {
                "Capacity_Maximum": 5120,
                "Current_DC": 2.0950622981079836,
                "DesignedCapacity": 5120,
                "Details": {
                    "Manufacturer": "BYD",
                    "Model": "BYD Battery-Box Premium HV",
                    "Serial": "P030T020Z2103032208     "
                },
                "Enable": 1,
                "StateOfCharge_Relative": 86.099999999999994,
                "Status_BatteryCell": 3.0,
                "Temperature_Cell": 23.0,
                "TimeStamp": 1638155622.0,
                "Voltage_DC": 216.69999999999999
            },
            "Modules": [ ]
        }
    },
    "Head": {
        "RequestArguments": {
            "DeviceId": "0",
            "Scope": "Device"
        },
        "Status": {
            "Code": 0,
            "Reason": "",
            "UserMessage": ""
        },
        "Timestamp": "2021-11-29T03:13:43+00:00"
    }
}

Also consider naming it storage instead or battery to match the API.