Homey Community Forum

2 device crontasks and latest added one is run twice, 1st is ignored

#1

Hi devs,

I hope you can help me with this. It is probably something stupid. I added 2 devices of the same type with a different api key and both need to have a crontask which runs every 5 min. With 1 device there is no problem and with 2 devices , the latest is running twice and 1st I don’t see it anymore

thanks

the code https://github.com/biemond/com.athom.zevercloud/blob/master/drivers/plant/device.js#L21

the output with the double [ManagerDrivers] [plant] [1] refresh now 1:45 PM

2019-02-18 13:40:08 [log] [MyApp] ZeverCloud app is running...
2019-02-18 13:40:08 [log] [ManagerDrivers] [plant] Plant driver has been inited
2019-02-18 13:41:00 [log] [ManagerDrivers] [plant] Plant id jxpyf
2019-02-18 13:41:09 [log] [ManagerDrivers] [plant] [0] plant has been inited
2019-02-18 13:41:09 [log] [ManagerDrivers] [plant] [0] key abc
2019-02-18 13:41:09 [log] [ManagerDrivers] [plant] [0] device settings {"apikey":"abc"}
2019-02-18 13:41:10 [log] [ManagerDrivers] [plant] [0] device added:  g2ur4
2019-02-18 13:41:10 [log] [ManagerDrivers] [plant] [0] The task has not been registered yet, registering task: zeversolar_plant_g2ur4
2019-02-18 13:41:10 [log] [ManagerDrivers] [plant] [0] pollSeverCloud settings {"apikey":"abc"}
url /api/v1/getPlantOverview?key=abc
2019-02-18 13:41:10 [log] [ManagerDrivers] [plant] ZeverCloud - Pairing is finished (done or aborted) 
2019-02-18 13:41:11 [log] [ManagerDrivers] [plant] [0] refresh now 1:41 PM
2019-02-18 13:41:11 [log] [ManagerDrivers] [plant] [0] Received data
2019-02-18 13:41:11 [log] [ManagerDrivers] [plant] [0] object {"sid":8025,"ludt":"2019-02-18 13:41:24","E-Today":{"unit":"kWh","value":5.5},"E-Month":{"unit":"kWh","value":81.22},"E-Total":{"unit":"MWh","value":4.78},"TotalYield":{"unit":"€","value":3343.64},"CO2Avoided":{"unit":"T","value":3.82},"Power":{"unit":"kW","value":1.38}}
2019-02-18 13:41:11 [log] [ManagerDrivers] [plant] [0] update date 2019-02-18 13:41:24
2019-02-18 13:41:11 [log] [ManagerDrivers] [plant] [0] triggerPowerAbove1000WFlow

2019-02-18 13:41:26 [log] [ManagerDrivers] [plant] Plant id vakha
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] plant has been inited
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] key cde
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] device settings {"apikey":"cde"}
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] device added:  zl6o5
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] The task has not been registered yet, registering task: zeversolar_plant_zl6o5
2019-02-18 13:41:54 [log] [ManagerDrivers] [plant] [1] pollSeverCloud settings {"apikey":"cde"}
url /api/v1/getPlantOverview?key=cde
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] [1] refresh now 1:41 PM
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] [1] Received data
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] [1] object {"sid":53121,"ludt":"2019-02-18 13:41:30","E-Today":{"unit":"kWh","value":2.3},"E-Month":{"unit":"kWh","value":25.36},"E-Total":{"unit":"kWh","value":304.37},"TotalYield":{"unit":"€","value":212.99},"CO2Avoided":{"unit":"kg","value":243.5},"Power":{"unit":"W","value":232}}
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] [1] update date 2019-02-18 13:41:30
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] [1] triggerPowerAbove100WFlow
2019-02-18 13:41:55 [log] [ManagerDrivers] [plant] ZeverCloud - Pairing is finished (done or aborted) 
2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud settings {"apikey":"cde"}
url /api/v1/getPlantOverview?key=cde
2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud settings {"apikey":"cde"}
url /api/v1/getPlantOverview?key=cde

2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] refresh now 1:45 PM
2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] Received data
2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] object {"sid":53121,"ludt":"2019-02-18 13:41:30","E-Today":{"unit":"kWh","value":2.3},"E-Month":{"unit":"kWh","value":25.36},"E-Total":{"unit":"kWh","value":304.37},"TotalYield":{"unit":"€","value":212.99},"CO2Avoided":{"unit":"kg","value":243.5},"Power":{"unit":"W","value":232}}
2019-02-18 13:45:00 [log] [ManagerDrivers] [plant] [1] update date 2019-02-18 13:41:30

2019-02-18 13:45:02 [log] [ManagerDrivers] [plant] [1] refresh now 1:45 PM
2019-02-18 13:45:02 [log] [ManagerDrivers] [plant] [1] Received data
2019-02-18 13:45:02 [log] [ManagerDrivers] [plant] [1] object {"sid":53121,"ludt":"2019-02-18 13:41:30","E-Today":{"unit":"kWh","value":2.3},"E-Month":{"unit":"kWh","value":25.36},"E-Total":{"unit":"kWh","value":304.37},"TotalYield":{"unit":"€","value":212.99},"CO2Avoided":{"unit":"kg","value":243.5},"Power":{"unit":"W","value":232}}
2019-02-18 13:45:02 [log] [ManagerDrivers] [plant] [1] update date 2019-02-18 13:41:clock1030: ```
#2

Instead of this:

task.on('run', () => this.pollSeverCloud(settings))

Can you try this:

task.on('run', settings => this.pollSeverCloud(settings))
#3

thanks, almost there but that is already better.
only need to solve that it updates the right device. I see 2 times plant 1 instead of also 0 with 1

Do I need to add more like add device to the crontask.

thanks again.

#4

So even though both run handlers run “inside” of device 1, you get the settings for device 0 in one handler and for device 1 in the other handler?

#5

correct

all is in plant 1 , settings is from plant 0 and 1 of plant 1

2019-02-18 15:40:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud device name zeversolar_plant_1p5bc
2019-02-18 15:40:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud device settings {"id":"1p5bc","apikey":"bbbbbbb"}
node_modules settings {"id":"cqhi8","apikey":"aaaaaa"}
node_modules url /api/v1/getPlantOverview?key=aaaaaa

2019-02-18 15:40:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud settings {"id":"1p5bc","apikey":"bbbbbbb"}
2019-02-18 15:40:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud device name zeversolar_plant_1p5bc
2019-02-18 15:40:00 [log] [ManagerDrivers] [plant] [1] pollSeverCloud device settings {"id":"1p5bc","apikey":"bbbbbbb"}
node_modules settings {"id":"1p5bc","apikey":"bbbbbbb"}
node_modules url /api/v1/getPlantOverview?key=bbbbbbb

2019-02-18 15:40:01 [log] [ManagerDrivers] [plant] [1] refresh now 3:40 PM
2019-02-18 15:40:01 [log] [ManagerDrivers] [plant] [1] Received data
2019-02-18 15:40:01 [log] [ManagerDrivers] [plant] [1] object {"sid":8025,"ludt":"2019-02-18 15:41:24","E-Today":{"unit":"kWh","value":7.4},"E-Month":{"unit":"kWh","value":83.32},"E-Total":{"unit":"MWh","value":4.78},"TotalYield":{"unit":"€","value":3345.11},"CO2Avoided":{"unit":"T","value":3.82},"Power":{"unit":"W","value":583}}
2019-02-18 15:40:01 [log] [ManagerDrivers] [plant] [1] update date 2019-02-18 15:41:24


2019-02-18 15:40:02 [log] [ManagerDrivers] [plant] [1] refresh now 3:40 PM
2019-02-18 15:40:02 [log] [ManagerDrivers] [plant] [1] Received data
2019-02-18 15:40:02 [log] [ManagerDrivers] [plant] [1] object {"sid":53121,"ludt":"2019-02-18 15:37:30","E-Today":{"unit":"kWh","value":2.6},"E-Month":{"unit":"kWh","value":25.76},"E-Total":{"unit":"kWh","value":304.67},"TotalYield":{"unit":"€","value":213.27},"CO2Avoided":{"unit":"kg","value":243.74},"Power":{"unit":"W","value":185}}```
#6

That’s very strange, because it would mean that the run handler for one task is also being called for the other task.

Out of curiosity, can you try this code? I assume that you’re running firmware v2, which I’m not, so can’t test myself:

const Homey = require('homey');

module.exports = class MyApp extends Homey.App {

  async onInit() {
    this.log('MyApp is running');
    const task1 = await this.task('task1');
    const task2 = await this.task('task2');

    task1.on('run', settings => {
      this.log('RUN#1', settings);
    });

    task2.on('run', settings => {
      this.log('RUN#2', settings);
    });
  }

  async task(name) {
    try {
      return await Homey.ManagerCron.getTask(name);
      this.log('YES', name);
    } catch(e) {
      this.log('NO ', name);
      return await Homey.ManagerCron.registerTask(name, '* * * * *', { name })
    }
  }
}

(run that instead of your normal app.js)

#7
2019-02-18 15:51:57 [log] [MyApp] MyApp is running
2019-02-18 15:51:57 [log] [MyApp] NO  task1
2019-02-18 15:51:57 [log] [ManagerDrivers] [plant] Plant driver has been inited
2019-02-18 15:51:57 [log] [MyApp] NO  task2
2019-02-18 15:52:00 [log] [MyApp] RUN#2 { name: 'task2' }
2019-02-18 15:52:00 [log] [MyApp] RUN#2 { name: 'task1' }```
#8

Okay, that looks like a bug to me! It’s triggering run on the second task only.

#9

thanks for all your help, really great.

what’s next I can report this issue somewhere.

#10

I see this one

1 Like
#11

Yeah, that’s the same problem :frowning: