zinen / node-red-contrib-nibeuplink

1 stars 0 forks source link

support of addition API calls #1

Closed chri46 closed 1 year ago

chri46 commented 1 year ago

Hi, Are you able to add following calls to your node? [GET api/v1/systems/{systemId}/serviceinfo/categories] [GET api/v1/systems/{systemId}/serviceinfo/categories/{categoryId}] and [GET api/v1/systems/{systemId}/serviceinfo/categories?systemUnitID=1] [GET api/v1/systems/{systemId}/serviceinfo/categories/{categoryId}?systemUnitID=1]

zinen commented 1 year ago

This node returns all data from API call to api/v1/systems/{systemId}/serviceinfo/categories as you can see here(code from this node): https://github.com/zinen/node-red-contrib-nibeuplink/blob/3e5d00a81a72d878baccfb8d7eb8a5e3a567c768/nibeuplink.js#L54

and then this from the API handler(external code repo) to explain what getAllParameter covers:

https://github.com/zinen/node-nibe-fetcher-promise/blob/02cb69665426653ed11f1021a8817107f636da8c/index.js#L285-L287

I might be wrong here. But I though that this approach would return all data from NIBE Uplink into to node-red and some change or swtich nodes could filter to your desired data level.

What is the use case for this request?

chri46 commented 1 year ago

use-case is to obtain additional values, which are not available in api/v1/systems/{systemId}/serviceinfo/categories call. the combination of smo40 and f2120 heatpump has more parameters of interest, which are available when calling the api listed before and those 2: GET api/v1/systems/{systemId}/status/system GET api/v1/systems/{systemId}/status/systemUnit/{systemUnitId}

api/v1/systems/{systemId}/serviceinfo/categories provides 8 out of 25 metrics of interest. the rest is retrieved with the apis I listed - mainly GET api/v1/systems/{systemId}/serviceinfo/categories/{categoryId} and GET api/v1/systems/{systemId}/serviceinfo/categories/{categoryId}?systemUnitID=1

zinen commented 1 year ago

Yet untested but I started working on a branch more-categories to address this

chri46 commented 1 year ago

I took a simple approach to achieve what I am after - neither skilled nor advanced java dev ;-)

in index.js

async getServiceInfoSTATUS() {
    if (!this.options.systemId) await this.getSystems()
    const payload = await this.getURLPath(`api/v1/systems/${this.options.systemId}/serviceinfo/categories/STATUS`, { parameters: true })
    return payload
  }
  async getServiceInfoSystem_1() {
    if (!this.options.systemId) await this.getSystems()
    const payload = await this.getURLPath(`api/v1/systems/${this.options.systemId}/serviceinfo/categories/SYSTEM_1`, { parameters: true })
    return payload
  }
  async getServiceInfoActiveCooling() {
    if (!this.options.systemId) await this.getSystems()
    const payload = await this.getURLPath(`api/v1/systems/${this.options.systemId}/serviceinfo/categories/ACTIVE_COOLING_2_PIPE`, { parameters: true })
    return payload
  }
  async getServiceInfoSTATUS_ID1() {
    if (!this.options.systemId) await this.getSystems()
    const payload = await this.getURLPath(`api/v1/systems/${this.options.systemId}/serviceinfo/categories/STATUS?systemUnitID=1`, { parameters: true })
    return payload
  }
  async getServiceInfoCPR_Info() {
    if (!this.options.systemId) await this.getSystems()
    const payload = await this.getURLPath(`api/v1/systems/${this.options.systemId}/serviceinfo/categories/CPR_INFO_EP14?systemUnitID=1`)
    return payload
  }

and in nibeuplink.js

function nibeuplinkNode(config) {
    RED.nodes.createNode(this, config)
    const node = this
    node.on('input', async function (msg, send, done) {
      node.server = RED.nodes.getNode(config.server)
      if (!node.server || !node.server.nibeuplinkClient) {
        node.status({ fill: 'red', text: 'Unknown config error' })
        done('Unknown config error')
        return
      }
      try {
        //node.status({ fill: '', text: 'Requesting AllParameters' })
        //msg.payload = await node.server.nibeuplinkClient.getAllParameters()
        //node.status({ fill: '', text: '' })
        //send(msg)
        var msg1 = {}
        var msg2 = {}
        var msg3 = {}
        var msg4 = {}
        var msg5 = {}
        node.status({ fill: '', text: 'Requesting ServiceInfoSTATUS' })
        msg1.payload = {StatusID0: await node.server.nibeuplinkClient.getServiceInfoSTATUS()}
        node.status({ fill: '', text: '' })
        node.status({ fill: '', text: 'Requesting ServiceInfoSystem_1' })
        msg2.payload = {System: await node.server.nibeuplinkClient.getServiceInfoSystem_1()}
        node.status({ fill: '', text: '' })
        node.status({ fill: '', text: 'Requesting ServiceInfoActiveCooling' })
        msg3.payload = {ActiveCooling: await node.server.nibeuplinkClient.getServiceInfoActiveCooling()}
        node.status({ fill: '', text: '' })
        node.status({ fill: '', text: 'Requesting ServiceInfoSTATUS_ID1' })
        msg4.payload = {StatusID1: await node.server.nibeuplinkClient.getServiceInfoSTATUS_ID1()}
        node.status({ fill: '', text: '' })
        node.status({ fill: '', text: 'Requesting ServiceInfoCPR_Info' })
        msg5.payload = {CPR_Info: await node.server.nibeuplinkClient.getServiceInfoCPR_Info()}
        node.status({ fill: '', text: '' })
        send([[msg1 , msg2 , msg3 , msg4 , msg5]])
        done()
zinen commented 1 year ago

I really try to adhere to the guide lines of node-red found here https://nodered.org/docs/creating-nodes/ and so I have taken a different approach.

Try updating to version 0.3.0 and import the example called basic. This should guide you how to get data from a slave systemUnitID both for the categories call and the status/system

How to import: Menu top right -> Import -> Examples -> node-red-contrib-nibeuplink -> basic

Let me know the outcome

chri46 commented 1 year ago

Exactly what I was after 👍

zinen commented 1 year ago

Perfect. Closing issue then :)