vrkttr / homebridge-vicare

Homebridge ViCare Plugin
https://www.vrkttr.de
MIT License
3 stars 0 forks source link

Error refreshing access token: Error: No refresh token available. #4

Closed sweh closed 3 months ago

sweh commented 3 months ago

Hi, first of all, thanks for sharing your plugin with us. I could authenticate with the Viessmann API without any problems, but when the plugin tries to retrieve the temperatures, I get an authentication error. Do you have any idea what's going wrong here?

[7/16/2024, 12:04:58 PM] [ViCareThermostat] Received authorization code: NfZ4e60yP…GYrRvH11vaEaq2Tj_b0
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Exchanging authorization code for access token...
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Successfully exchanged code for access token.
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Access Token: eyJraWQiOiI0ZWNhM2VkNi…bVkZrnKMn35BHOSPh9dWuyfKEZ73Lb8csG8
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Refresh Token: undefined
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Authentication successful, received access token.
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Received refresh token: undefined
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Saving tokens to file: {
  accessToken: 'eyJraWQiOiI0ZWNhM2VkNi…bVkZrnKMn35BHOSPh9dWuyfKEZ73Lb8csG8',
  refreshToken: undefined
}
[7/16/2024, 12:04:58 PM] [ViCareThermostat] Saved tokens to file.
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Retrieving installation IDs...
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Successfully retrieved installations: {
  cursor: { next: '' },
  data: [
    {
      id: XXXX,
      description: 'XXXX',
      address: [Object],
      registeredAt: '2018-07-31T12:29:37.951Z',
      updatedAt: '2024-07-11T15:35:58.422Z',
      aggregatedStatus: 'WorksProperly',
      servicedBy: null,
      heatingType: null,
      ownedByMaintainer: false,
      endUserWlanCommissioned: true,
      withoutViCareUser: false,
      installationType: 'Residential',
      buildingName: null,
      buildingEmail: null,
      buildingPhone: null,
      accessLevel: 'Owner',
      ownershipType: 'ResidentialEndUser'
    }
  ]
}
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Retrieving gateway IDs...
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Successfully retrieved gateways: {
  cursor: { next: '' },
  data: [
    {
      serial: '7571381754202202',
      version: '2.8.0.0',
      firmwareUpdateFailureCounter: 0,
      autoUpdate: false,
      createdAt: '2017-05-24T16:18:36.820Z',
      producedAt: '2017-05-23T09:55:27.000Z',
      lastStatusChangedAt: '2024-07-11T15:35:58.402Z',
      aggregatedStatus: 'WorksProperly',
      targetRealm: 'DC',
      gatewayType: 'VitoconnectOptolink',
      installationId: 112267,
      registeredAt: '2018-07-31T12:29:37.955Z',
      description: null,
      otaOngoing: false
    }
  ]
}
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Retrieved installation and gateway IDs.
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Added new accessory: Supply temperature
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Added new accessory: Main DHW temperature
[7/16/2024, 11:54:44 AM] [ViCareThermostat] Retrieving smart components...
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Successfully retrieved smart components: {
  data: [
    {
      id: 'avm-fritz',
      name: 'AVM Fritz!',
      selected: false,
      deleted: false
    },
    {
      id: 'bosch-smart-home',
      name: 'Bosch Smart Home',
      selected: false,
      deleted: false
    },
    { id: 'danfoss', name: 'Danfoss', selected: false, deleted: false },
    {
      id: 'digital-thermostats-discounts',
      name: 'Digitale Thermostate (Discounter / Baumarkt)',
      selected: false,
      deleted: false
    },
    { id: 'eve', name: 'Eve', selected: false, deleted: false },
    { id: 'eq-3', name: 'eQ-3', selected: false, deleted: false },
    {
      id: 'homematic-ip',
      name: 'Homematic IP',
      selected: false,
      deleted: false
    },
    {
      id: 'honeywell',
      name: 'Honeywell',
      selected: false,
      deleted: false
    },
    { id: 'knx', name: 'KNX', selected: false, deleted: false },
    { id: 'loxone', name: 'Loxone', selected: false, deleted: false },
    {
      id: 'magenta-smart-home',
      name: 'Magenta Smart Home',
      selected: false,
      deleted: false
    },
    { id: 'nest', name: 'Nest', selected: false, deleted: false },
    { id: 'netatmo', name: 'Netatmo', selected: false, deleted: false },
    { id: 'tado', name: 'Tado', selected: false, deleted: false },
    {
      id: 'wibutler',
      name: 'WiButler',
      selected: false,
      deleted: false
    }
  ]
}
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: avm-fritz, Name: AVM Fritz!, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: bosch-smart-home, Name: Bosch Smart Home, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: danfoss, Name: Danfoss, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: digital-thermostats-discounts, Name: Digitale Thermostate (Discounter / Baumarkt), Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: eve, Name: Eve, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: eq-3, Name: eQ-3, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: homematic-ip, Name: Homematic IP, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: honeywell, Name: Honeywell, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: knx, Name: KNX, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: loxone, Name: Loxone, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: magenta-smart-home, Name: Magenta Smart Home, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: nest, Name: Nest, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: netatmo, Name: Netatmo, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: tado, Name: Tado, Selected: false, Deleted: false
[7/16/2024, 11:54:45 AM] [ViCareThermostat] Component ID: wibutler, Name: WiButler, Selected: false, Deleted: false
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Fetching temperature from https://api.viessmann.com/iot/v1/features/installations/112267/gateways/7571381754202202/devices/0/features/heating.circuits.0.sensors.temperature.supply
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Access token expired, refreshing...
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Error refreshing access token: Error: No refresh token available.
    at ViCareThermostatPlatform.refreshAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:166:19)
    at ViCareThermostatAccessory.checkAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:472:21)
    at ViCareThermostatAccessory.getTemperature (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:404:10)
    at CurrentTemperature.emit (node:events:519:28)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2468:14
    at new Promise (<anonymous>)
    at CurrentTemperature.<anonymous> (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2466:12)
    at step (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:195:27)
    at Object.next (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:176:57)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:169:75
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Error refreshing access token: Error: No refresh token available.
    at ViCareThermostatPlatform.refreshAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:166:19)
    at ViCareThermostatAccessory.checkAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:472:21)
    at ViCareThermostatAccessory.getTemperature (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:404:10)
    at CurrentTemperature.emit (node:events:519:28)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2468:14
    at new Promise (<anonymous>)
    at CurrentTemperature.<anonymous> (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2466:12)
    at step (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:195:27)
    at Object.next (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:176:57)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:169:75
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Fetching temperature from https://api.viessmann.com/iot/v1/features/installations/112267/gateways/7571381754202202/devices/0/features/heating.dhw.temperature.main
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Access token expired, refreshing...
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Error refreshing access token: Error: No refresh token available.
    at ViCareThermostatPlatform.refreshAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:166:19)
    at ViCareThermostatAccessory.checkAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:472:21)
    at ViCareThermostatAccessory.getTemperature (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:404:10)
    at CurrentTemperature.emit (node:events:519:28)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2468:14
    at new Promise (<anonymous>)
    at CurrentTemperature.<anonymous> (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2466:12)
    at step (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:195:27)
    at Object.next (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:176:57)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:169:75
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Error refreshing access token: Error: No refresh token available.
    at ViCareThermostatPlatform.refreshAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:166:19)
    at ViCareThermostatAccessory.checkAccessToken (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:472:21)
    at ViCareThermostatAccessory.getTemperature (file:///var/lib/homebridge/node_modules/homebridge-vicare/index.js:404:10)
    at CurrentTemperature.emit (node:events:519:28)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2468:14
    at new Promise (<anonymous>)
    at CurrentTemperature.<anonymous> (/var/lib/homebridge/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2466:12)
    at step (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:195:27)
    at Object.next (/var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:176:57)
    at /var/lib/homebridge/node_modules/homebridge/node_modules/tslib/tslib.js:169:75
[7/16/2024, 11:54:47 AM] [ViCareThermostat] Unexpected response structure: {
  feature: 'heating.circuits.0.sensors.temperature.supply',
  gatewayId: '7571381754202202',
  deviceId: '0',
  timestamp: '2024-07-16T07:05:28.658Z',
  isEnabled: false,
  isReady: true,
  apiVersion: 1,
  uri: 'https://api.viessmann.com/iot/v1/features/installations/112267/gateways/7571381754202202/devices/0/features/heating.circuits.0.sensors.temperature.supply',
  properties: {},
  commands: {}
}
sweh commented 3 months ago

I could fix this by adding %20offline_access to the requested scopesin the authUrl. The a refresh_token is provided and its working.

I provided a PR here: https://github.com/vrkttr/homebridge-vicare/pull/5