longzheng / homebridge-fronius-inverter-lights

Homebridge plugin for Fronius inverter with smart meter as a lightbulb accessory
MIT License
9 stars 2 forks source link

Add instructions for enabling JSON API on newer inverters, and provide ability to customise the HomeKit Model and Serial #21

Open Shaun-R opened 1 week ago

Shaun-R commented 1 week ago

Searching the 'net for a Homebridge plugin for my Fronius PV inverter, fancy coming across a familiar name! I remember you wrote a certain iOS app to allow topping up a certain public transport smart card to solve a certain crappy mobile website issue, as I recall... :)

Anyway, your plugin works brilliantly mate! Thank you!

Newer Fronius inverters have a redesigned web interface. Before setting up your plugin, one must first login to the local web UI as Customer or Technician user, open the hamburger menu on the left, select Communication, select Solar API, then turn on Activate communication via Solar API, and finally select Save. Otherwise, the inverter does not make the JSON data available.

image

It might be worth adding this to the readme.md?

My feature request for this plugin would be to allow user customisation of the Serial Number and Model which appears in HomeKit (as seen in below screenshot)

IMG_0140

It appears that fronius-accessory.ts currently configures the Manufacturer and Model values (line 95-97), though I don't see references to a serial number in your code. Would it be possible to expose these as user-configurable fields in the config.schema.json and pass them through to this?

Thanks for your work!

longzheng commented 1 week ago

Hi Shaun, nice seeing you again too.

I'm travelling interstate this week but those suggestions makes a lot of sense. Will do when I get back.

For the model and serial, I wonder if the API contains any of that actually. Will investigate.

Shaun-R commented 1 week ago

Safe travels!

longzheng commented 1 week ago

@Shaun-R It looks like I can automatically get the inverter model(s) from the http://.../solar_api/v1/GetInverterInfo.cgi endpoint which returns a DT number.

{
   "Body" : {
      "Data" : {
         "1" : {
            "DT" : 115,
            "UniqueID" : "123456",
            ...
         }
      }
   },
   ...
}

Then I can lookup the number in http://.../solar_api/v1/data/DeviceDB_Data.json

{
  "Inverters": {
    "42": {
      "ProductName": "Symo Advanced 10.0-3-M",
      "DeviceFamily": "0",
      "NominalPower": "10000",
      "PhaseCountAC": "1"
    },
    "43": {
      "ProductName": "Symo Advanced 20.0-3-M",
      "DeviceFamily": "28",
      "NominalPower": "20000",
      "PhaseCountAC": "3"
    },
    ...
  }
}

I'm thinking I can use the inverter ProductName as the model and UniqueID as the serial, but because one system can have multiple inverters (which I merge into one PV accessory), I guess they'll just need to be joined with an ampersand. Does that sound reasonable to you?

Shaun-R commented 6 days ago

Nice investigative work! Joining multiple UniqueID’s in the format [UniqueID][space][ampersand][space][UniqueID] seems quite reasonable to me!

longzheng commented 2 days ago

@Shaun-R I started working on this but then I ran into a major problem, HomeKit/Homebridge seems to only initialize the accessory information (manufacturer, model, serial) only once when the accessory is loaded, and it can't be dynamically updated.

See https://stackoverflow.com/questions/75571300/homebridge-update-accessoryinformation and https://github.com/homebridge/homebridge/issues/1643

The only workaround I can think of is changing how the plugin platform initially creates the accessories, and introduce a delay there to wait for the API query to finish, then create the accessories with the metadata already loaded. I think that'll technically work, but the downside is that it will delay the "bridge startup" which isn't a big deal but is advised against.

longzheng commented 2 days ago

@Shaun-R I've published a new beta version 1.7.0-beta.1 with the above changes, can you test

image