easimon / shelly-exporter

Prometheus exporter for shelly devices
5 stars 1 forks source link

Problem with Shelly Plus1PM and Missing "Slot" in Gen2ShellyDeviceInfo #125

Open ClintEastwood1337 opened 15 hours ago

ClintEastwood1337 commented 15 hours ago

Hi easimon, when interacting with a Shelly Plus1PM device, the current firmware introduces a new slot field in the response from http://192.168.178.23/rpc/Shelly.GetDeviceInfo.
However, this field is not yet included in the Gen2ShellyDeviceInfo data class, causing deserialization issues.

The data class currently defined in src/main/kotlin/click/dobel/shelly/exporter/client/api/gen2/Gen2ShellyDeviceInfo.kt:

package click.dobel.shelly.exporter.client.api.gen2

import com.fasterxml.jackson.annotation.JsonProperty

data class Gen2ShellyDeviceInfo(
  @JsonProperty("name")
  val name: String,
  @JsonProperty("id")
  val id: String,
  @JsonProperty("mac")
  val mac: String,
  @JsonProperty("model")
  val model: String,
  @JsonProperty("gen")
  val gen: Int,
  @JsonProperty("fw_id")
  val firmwareId: String,
  @JsonProperty("ver")
  val version: String,
  @JsonProperty("app")
  val app: String,
  @JsonProperty("auth_en")
  val authEnabled: Boolean,
  @JsonProperty("auth_domain")
  val authDomain: String?,
)

The new slot field is missing, leading to the following sample response being problematic for deserialization: http://192.168.178.23/rpc/Shelly.GetDeviceInfo

{
  "name": null,
  "id": "shellyplus1pm-78ee4cc93840",
  "mac": "78EE4CC93840",
  "slot": 0,
  "model": "SNSW-001P16EU",
  "gen": 2,
  "fw_id": "20241011-114445/1.4.4-g6d2a586",
  "ver": "1.4.4",
  "app": "Plus1PM",
  "auth_en": true,
  "auth_domain": "shellyplus1pm-78ee4cc93840"
}

Here’s a relevant snippet from the debug log showing the issue:

2024-11-24T10:56:18.590Z  INFO 1 --- [           main] c.d.s.e.ShellyExporterApplicationKt      : Started ShellyExporterApplicationKt in 17.983 seconds (process running for 20.642)
2024-11-24T10:56:18.600Z DEBUG 1 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2024-11-24T10:56:18.615Z DEBUG 1 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
2024-11-24T10:56:18.626Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen2DeviceRegistry       : Updating device addresses.
2024-11-24T10:56:18.756Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo
2024-11-24T10:56:19.266Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T10:56:19.475Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T10:56:19.483Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo]
2024-11-24T10:56:19.604Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo
2024-11-24T10:56:19.606Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T10:56:19.637Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T10:56:19.639Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo]
2024-11-24T10:56:19.645Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo
2024-11-24T10:56:19.649Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T10:56:19.679Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T10:56:19.681Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo]
2024-11-24T10:56:19.687Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo
2024-11-24T10:56:19.690Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T10:56:19.718Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T10:56:19.720Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo]
2024-11-24T10:56:19.730Z  WARN 1 --- [   scheduling-1] c.d.s.exporter.client.ShellyGen2Client   : GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo: HTTP Request failure: Error while extracting response for type [class click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo] and content type [application/json]
2024-11-24T10:56:19.740Z  WARN 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen2DeviceRegistry       : Could not discover device at [192.168.178.23].
2024-11-24T10:56:19.755Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen2DeviceRegistry       : Added 0, removed 0, current amount: 0 devices.
2024-11-24T10:56:19.758Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen1DeviceRegistry       : Updating device addresses.
2024-11-24T10:56:19.758Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen1DeviceRegistry       : Added 0, removed 0, current amount: 0 devices.

Let me know if any additional details are needed.

I have no idea where this slot comes from in my case, it's not in the official documentation either https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly/#shellygetdeviceinfo

easimon commented 14 hours ago

Hi. I cannot check this at the moment, but I assume, the slot field is not the problem (it is just ignored).

Instead, I think the error stems from the device missing a name (it is null in the response). I know there are two places to set a device name in the Shelly App, and there is also a setting to keep them synchronized. I never understood why there are two places but probably you can fix it by setting the name in both (and/or toggling the sync option).

ClintEastwood1337 commented 7 hours ago

We’ve made some progress. I have equated the names and also tried out the sync The "GetDeviceInfo" call is now working; however, I still have an issue with the "GetStatus" call.

Here is an excerpt from the debug log:

2024-11-24T18:09:32.618Z  INFO 1 --- [           main] c.d.s.e.ShellyExporterApplicationKt      : Started ShellyExporterApplicationKt in 18.838 seconds (process running for 21.708)
2024-11-24T18:09:32.628Z DEBUG 1 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2024-11-24T18:09:32.647Z DEBUG 1 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
2024-11-24T18:09:32.650Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen2DeviceRegistry       : Updating device addresses.
2024-11-24T18:09:32.780Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetDeviceInfo
2024-11-24T18:09:33.271Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T18:09:33.474Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T18:09:33.482Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyDeviceInfo]
2024-11-24T18:09:33.629Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen2DeviceRegistry       : Added 1, removed 0, current amount: 1 devices.
2024-11-24T18:09:33.658Z  INFO 1 --- [   scheduling-1] c.d.s.e.metrics.ShellyGen2Metrics        : Registering ShellyDevice(mac=78EE4CC93840, address=192.168.178.23, name=Plus1PM, type=SNSW-001P16EU, firmwareVersion=20241011-114445/1.4.4-g6d2a586).
2024-11-24T18:09:33.745Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetStatus
2024-11-24T18:09:35.268Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T18:09:35.351Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T18:09:35.353Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyStatus]
2024-11-24T18:09:35.376Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetStatus
2024-11-24T18:09:35.378Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T18:09:35.441Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T18:09:35.443Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyStatus]
2024-11-24T18:09:35.453Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetStatus
2024-11-24T18:09:35.455Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T18:09:35.525Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T18:09:35.526Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyStatus]
2024-11-24T18:09:35.534Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : HTTP GET http://192.168.178.23/rpc/Shelly.GetStatus
2024-11-24T18:09:35.537Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Accept=[application/json, application/*+json]
2024-11-24T18:09:35.597Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Response 200 OK
2024-11-24T18:09:35.598Z DEBUG 1 --- [   scheduling-1] o.s.web.client.RestTemplate              : Reading to [click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyStatus]
2024-11-24T18:09:35.609Z  WARN 1 --- [   scheduling-1] c.d.s.exporter.client.ShellyGen2Client   : GET http://192.168.178.23/rpc/Shelly.GetStatus: HTTP Request failure: Error while extracting response for type [class click.dobel.shelly.exporter.client.api.gen2.Gen2ShellyStatus] and content type [application/json]
2024-11-24T18:09:35.613Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen1DeviceRegistry       : Updating device addresses.
2024-11-24T18:09:35.614Z  INFO 1 --- [   scheduling-1] c.d.s.e.d.ShellyGen1DeviceRegistry       : Added 0, removed 0, current amount: 0 devices.

When accessing http://192.168.178.23/rpc/Shelly.GetStatus, I receive the following response:

{
  "ble": {

  },
  "cloud": {
    "connected": true
  },
  "input:0": {
    "id": 0,
    "state": false
  },
  "mqtt": {
    "connected": false
  },
  "switch:0": {
    "id": 0,
    "source": "init",
    "output": false,
    "apower": 0,
    "voltage": 238.1,
    "current": 0,
    "aenergy": {
      "total": 0,
      "by_minute": [0, 0, 0],
      "minute_ts": 1732472940
    },
    "temperature": {
      "tC": 40.1,
      "tF": 104.2
    }
  },
  "sys": {
    "mac": "78EE4CC93840",
    "restart_required": false,
    "time": "19:29",
    "unixtime": 1732472984,
    "uptime": 1369,
    "ram_size": 253572,
    "ram_free": 132860,
    "fs_size": 393216,
    "fs_free": 106496,
    "cfg_rev": 21,
    "kvs_rev": 1,
    "schedule_rev": 5,
    "webhook_rev": 0,
    "available_updates": {

    },
    "reset_reason": 1
  },
  "wifi": {
    "sta_ip": "192.168.178.23",
    "status": "got ip",
    "ssid": "#####",
    "rssi": -29
  },
  "ws": {
    "connected": false
  }
}

One more piece of information: I am currently operating the Shelly without a consumer, and have only connected it for set-up purposes