unparagoned / njsTuya

Openhab interface for Tuya home automation devices sold under various names
27 stars 11 forks source link

Error in openHAB #19

Closed edwolfe3 closed 4 years ago

edwolfe3 commented 5 years ago

I have a rule that turns on 2 other switches -- remote subwoofer (HomeCinema_Subwoofer) and seat rumblers (HomeCinema_SeatRumblers) -- when my theater rack (HomeCinema_Rack) turns on. I'm getting the following error in the openHAB logs when I issue the command:

2019-05-09 13:03:28.039 [ome.event.ItemCommandEvent] - Item 'GF_HomeCinema_Rack' received command ON

I've been struggling with this for a few days now and can't seem to figure it out. It seems like it isn't getting a response from the device, but why?

2019-05-09 13:03:28.074 [vent.ItemStateChangedEvent] - GF_HomeCinema_Rack changed from OFF to ON

2019-05-09 13:03:28.081 [GroupItemStateChangedEvent] - gPower changed from OFF to ON through GF_HomeCinema_Rack

==> /var/log/openhab2/openhab.log <==

2019-05-09 13:03:28.101 [INFO ] [se.smarthome.model.script.CinemaRack] - Running Script

2019-05-09 13:03:28.109 [INFO ] [se.smarthome.model.script.CinemaRack] - Turning ON

==> /var/log/openhab2/events.log <==

2019-05-09 13:03:28.113 [ome.event.ItemCommandEvent] - Item 'cmdSmartLife_HomeCinema_Rack_Args' received command ON

2019-05-09 13:03:28.131 [ome.event.ItemCommandEvent] - Item 'GF_HomeCinema_SeatRumblers' received command ON

2019-05-09 13:03:28.139 [ome.event.ItemCommandEvent] - Item 'GF_HomeCinema_Subwoofer' received command ON

==> /var/log/openhab2/openhab.log <==

2019-05-09 13:03:28.124 [INFO ] [.model.script.SmartLife command exec] - Result: (node:27491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:189:5)

(node:27491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:189:5)

(node:27491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

==> /var/log/openhab2/events.log <==

2019-05-09 13:03:28.148 [ome.event.ItemCommandEvent] - Item 'cmdSmartLife_HomeCinema_Rack' received command ON

2019-05-09 13:03:28.153 [nt.ItemStatePredictedEvent] - cmdSmartLife_HomeCinema_Rack_Args predicted to become ON

2019-05-09 13:03:28.174 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Rack_Args changed from OFF to ON

2019-05-09 13:03:28.178 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Rack changed from OFF to ON

2019-05-09 13:03:28.212 [vent.ItemStateChangedEvent] - GF_HomeCinema_SeatRumblers changed from OFF to ON

2019-05-09 13:03:28.222 [vent.ItemStateChangedEvent] - GF_HomeCinema_Subwoofer changed from OFF to ON

2019-05-09 13:03:28.225 [nt.ItemStatePredictedEvent] - cmdSmartLife_HomeCinema_Rack predicted to become ON

2019-05-09 13:03:28.231 [ome.event.ItemCommandEvent] - Item 'cmdSmartLife_HomeCinema_SeatRumblers_Args' received command ON

2019-05-09 13:03:28.241 [nt.ItemStatePredictedEvent] - cmdSmartLife_HomeCinema_SeatRumblers_Args predicted to become NULL

2019-05-09 13:03:28.265 [ome.event.ItemCommandEvent] - Item 'cmdSmartLife_HomeCinema_Subwoofer_Args' received command ON

2019-05-09 13:03:28.273 [nt.ItemStatePredictedEvent] - cmdSmartLife_HomeCinema_Subwoofer_Args predicted to become ON

==> /var/log/openhab2/openhab.log <==

2019-05-09 13:03:28.285 [INFO ] [.model.script.SmartLife command exec] - Result: OFF

==> /var/log/openhab2/events.log <==

2019-05-09 13:03:28.295 [ome.event.ItemCommandEvent] - Item 'cmdSmartLife_HomeCinema_Subwoofer' received command ON

2019-05-09 13:03:28.327 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Subwoofer_Args changed from OFF to ON

2019-05-09 13:03:28.331 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Subwoofer changed from OFF to ON

2019-05-09 13:03:28.334 [nt.ItemStatePredictedEvent] - cmdSmartLife_HomeCinema_Subwoofer predicted to become ON

2019-05-09 13:03:31.288 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Rack changed from ON to OFF

2019-05-09 13:03:31.309 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Rack_Output changed from (node:27491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:189:5)

(node:27491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:189:5)

(node:27491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. to (node:27935) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27935) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2019-05-09 13:03:31.380 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Subwoofer changed from ON to OFF

2019-05-09 13:03:31.389 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Subwoofer_Output changed from OFF to (node:27958) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27958) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27958) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27958) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27958) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27958) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2019-05-09 13:03:31.394 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Rack_Output changed from (node:27935) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27935) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. to (node:27945) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27945) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27945) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27945) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27945) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27945) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2019-05-09 13:03:31.818 [vent.ItemStateChangedEvent] - cmdSmartLife_HomeCinema_Subwoofer_Output changed from (node:27958) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27958) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27958) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:27958) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

at processTicksAndRejections (internal/process/task_queues.js:89:5)

at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:187:5)

(node:27958) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:27958) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. to ON

unparagoned commented 5 years ago

It looks like there is an error in the response and the code isn't displaying the error. Can you run the code in debug mode. So just stick "DEBUG=*" in-front of the command being run, or try from the console for easier testing.

DEBUG=* node njstuya.js -mode cloud -id 12312312312 COMMAND
edwolfe3 commented 5 years ago

I've tried it from the command line, but I don't have any problem there (does that mean it is an running under opoenHAB or maybe when an openHAB rule is involved? I changed the exec command to

node DEBUG=* /etc/openhab2/scripts/node_modules/njstuya/njstuya.js -mode cloud -id 0620004568c63abd5ad0 %2$s

and received LESS output (does it go to a file somewhere?). It did turn the switch off but did not trigger my rule. This is what I received in the openHAB log:

2019-05-09 14:37:33.026 [me.event.ThingUpdatedEvent] - Thing 'exec:command:smartlife:cinema:rack' has been updated.

2019-05-09 14:37:34.466 [ome.event.ItemCommandEvent] - Item 'GF_HomeCinema_Rack' received command OFF

2019-05-09 14:37:34.479 [vent.ItemStateChangedEvent] - GF_HomeCinema_Rack changed from ON to OFF
edwolfe3 commented 5 years ago

I changed my openHAB exec binding to point to a python script which runs njsTuya.js. This is what I got in the logs now:

2019-05-09T16:26:18.741Z cloudtuya {

  uri: 'https://px1.tuyaeu.com/homeassistant/skill',

  method: 'POST',

  headers: { 'Content-Type': 'application/json' },

  json: {

    header: { name: 'turnOnOff', namespace: 'control', payloadVersion: 1 },

    payload: { accessToken: undefined, devId: '10670365bcddc2fa4c7c', value: 0 }

  }

}

2019-05-09T16:26:19.253Z cloudtuya undefined

(node:4382) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'header' of undefined

    at setStateCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:176:11)

    at processTicksAndRejections (internal/process/task_queues.js:89:5)

    at async runCloud (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:189:5)
edwolfe3 commented 5 years ago

It looks like the script or cloud code or ... can't handle calls being put through it too quickly. I created a rule as follows:

rule "Sync status with outside controllers"
when
    Time cron "5 * * * * ?"
then
    cmdSmartLife_Attic_CoolingFans_Args.sendCommand("STATE")
    cmdSmartLife_Attic_CoolingFans.sendCommand(ON)

//    cmdSmartLife_HomeCinema_Rack_Args.sendCommand("STATE")
//    cmdSmartLife_HomeCinema_Rack.sendCommand(ON)

//    cmdSmartLife_HomeCinema_Subwoofer_Args.sendCommand("STATE")
//    cmdSmartLife_HomeCinema_Subwoofer.sendCommand(ON)

//    cmdSmartLife_HomeCinema_SeatRumblers_Args.sendCommand("STATE")
//    cmdSmartLife_HomeCinema_SeatRumblers.sendCommand(ON)

//    cmdSmartLife_HomeCinema_ShuffleboardScoreboard_Args.sendCommand("STATE")
//    cmdSmartLife_HomeCinema_ShuffleboardScoreboard.sendCommand(ON)

//    cmdSmartLife_HomeCinema_ConcessionStand_Args.sendCommand("STATE")
//    cmdSmartLife_HomeCinema_ConcessionStand.sendCommand(ON)
end

When I run it as is, it runs fine. However, if I activate any of the commented out lines, I start getting a lot of errors similar to errors shown in previous replies to this issue. It is either "Cannot read property 'header' of undefined" on line 176 of njstuya.js or "Cannot read property 'map' of undefined on line 152 of cloudtuya.js

Is this something you need to investigate or do you have a thought as to why running the script multiple times in quick succession causes this?

unparagoned commented 5 years ago

Oh, yeh you should have some sort of delay or let the script return before running it again. There used to be protection against running the script again when it was still running but that was for linux only. Yeh, stick in a delay or something between running the script in close succession. For offline it used to be a massive problem and you had to stick long delays in and I had some of that in the script but they aren't required for off-line mode really now. It may still be an issue for cloud mode. So stick in small delays in rules. I'll add this to the backlog and see if I can reproduce it and properly identify the issue.