Trigger a script on device value change

Hello everyone!

I am currently having a problem with Gladys to turn off the TV or turn it on.

I developed a small module using the hdmi-cec function by starting from the shellJs library and the help of C4rlit0/gladys-googledrive:
https://github.com/vincentBesseau/gladys-hdmiCec

I was able to test my unit scripts and it works.

Thanks to the Network Scanner module, Gladys found my TV.

I was able to add my TV as a device:

I then created two scenarios when the value of my device changes:

However, when I change the value of my device via the button

I end up with these errors that I must admit, I do not understand:

0|gladys | Sending 500 (« Server Error ») response:
0|gladys | TypeError: Cannot read property ‹ exec › of undefined
0|gladys | at /home/pi/gladys/api/core/devicetype/deviceType.exec.js:26:56
0|gladys | at tryCatcher (/home/pi/gladys/node_modules/bluebird/js/release/util.js:16:23)
0|gladys | at Promise._settlePromiseFromHandler (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:512:31)
0|gladys | at Promise._settlePromise (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:569:18)
0|gladys | at Promise._settlePromise0 (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:614:10)
0|gladys | at Promise._settlePromises (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:693:18)
0|gladys | at Promise._fulfill (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:638:18)
0|gladys | at /home/pi/gladys/node_modules/bluebird/js/release/nodeback.js:42:21
0|gladys | at /home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:120:16
0|gladys | at Object.poolfully [as releaseConnection] (/home/pi/gladys/node_modules/sails-mysql/lib/connections/release.js:28:12)
0|gladys | at Query._callback (/home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:105:35)
0|gladys | at Query.Sequence.end (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
0|gladys | at Query._handleFinalResultPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
0|gladys | at Query.EofPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
0|gladys | at Protocol._parsePacket (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:280:23)
0|gladys | at Parser.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Parser.js:73:12)
0|gladys | at Protocol.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:39:16)
0|gladys | at Socket. (/home/pi/gladys/node_modules/mysql/lib/Connection.js:96:28)
0|gladys | at emitOne (events.js:96:13)
0|gladys | at Socket.emit (events.js:188:7)
0|gladys | at readableAddChunk (_stream_readable.js:176:18)
0|gladys | at Socket.Readable.push (_stream_readable.js:134:10)
0|gladys | at TCP.onread (net.js:547:20)
0|gladys | Server Error:
0|gladys | TypeError: Cannot read property ‹ exec › of undefined
0|gladys | at /home/pi/gladys/api/core/devicetype/deviceType.exec.js:26:56
0|gladys | at tryCatcher (/home/pi/gladys/node_modules/bluebird/js/release/util.js:16:23)
0|gladys | at Promise._settlePromiseFromHandler (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:512:31)
0|gladys | at Promise._settlePromise (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:569:18)
0|gladys | at Promise._settlePromise0 (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:614:10)
0|gladys | at Promise._settlePromises (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:693:18)
0|gladys | at Promise._fulfill (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:638:18)
0|gladys | at /home/pi/gladys/node_modules/bluebird/js/release/nodeback.js:42:21
0|gladys | at /home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:120:16
0|gladys | at Object.poolfully [as releaseConnection] (/home/pi/gladys/node_modules/sails-mysql/lib/connections/release.js:28:12)
0|gladys | at Query._callback (/home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:105:35)
0|gladys | at Query.Sequence.end (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
0|gladys | at Query._handleFinalResultPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
0|gladys | at Query.EofPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
0|gladys | at Protocol._parsePacket (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:280:23)
0|gladys | at Parser.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Parser.js:73:12)
0|gladys | at Protocol.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:39:16)
0|gladys | at Socket. (/home/pi/gladys/node_modules/mysql/lib/Connection.js:96:28)
0|gladys | at emitOne (events.js:96:13)
0|gladys | at Socket.emit (events.js:188:7)
0|gladys | at readableAddChunk (_stream_readable.js:176:18)
0|gladys | at Socket.Readable.push (_stream_readable.js:134:10)
0|gladys | at TCP.onread (net.js:547:20)

Thank you for your help.

Hello @spenceur

Have you followed the mini tutorial on the website?
There is a hierarchy to be respected and apparently you haven’t done it, hence your errors. I therefore invite you to check out the following link Develop a module

For the explanation, in your logs you have this line

It indicates that Gladys was not able to find the exec file of the module. In fact, when you create a module, this file must imperatively be present and, moreover, in a folder named lib (which itself must be at the root of the module) because this is the file that will be called first and will redirect to the others (it’s like a central pillar if you will).

I hope I have been clear enough :grinning:

Hi @LepetitGeek :slight_smile:

First of all, thank you for replying to me =D
Indeed, I hadn’t noticed the mini tutorial :slight_smile: thanks for the link, it will be useful for me :stuck_out_tongue:.

I quickly tested creating this exec file at the root of the lib folder.

However, I still have the previous error, namely:

0|gladys | Sending 500 (« Server Error ») response:
0|gladys | TypeError: Cannot read property ‹ exec › of undefined
0|gladys | at /home/pi/gladys/api/core/devicetype/deviceType.exec.js:26:56
0|gladys | at tryCatcher (/home/pi/gladys/node_modules/bluebird/js/release/util.js:16:23)
0|gladys | at Promise._settlePromiseFromHandler (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:512:31)
0|gladys | at Promise._settlePromise (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:569:18)
0|gladys | at Promise._settlePromise0 (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:614:10)
0|gladys | at Promise._settlePromises (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:693:18)
0|gladys | at Promise._fulfill (/home/pi/gladys/node_modules/bluebird/js/release/promise.js:638:18)
0|gladys | at /home/pi/gladys/node_modules/bluebird/js/release/nodeback.js:42:21
0|gladys | at /home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:120:16
0|gladys | at Object.poolfully [as releaseConnection] (/home/pi/gladys/node_modules/sails-mysql/lib/connections/release.js:28:12)
0|gladys | at Query._callback (/home/pi/gladys/node_modules/sails-mysql/lib/connections/spawn.js:105:35)
0|gladys | at Query.Sequence.end (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
0|gladys | at Query._handleFinalResultPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
0|gladys | at Query.EofPacket (/home/pi/gladys/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
0|gladys | at Protocol._parsePacket (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:280:23)
0|gladys | at Parser.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Parser.js:73:12)
0|gladys | at Protocol.write (/home/pi/gladys/node_modules/mysql/lib/protocol/Protocol.js:39:16)
0|gladys | at Socket. (/home/pi/gladys/node_modules/mysql/lib/Connection.js:96:28)
0|gladys | at emitOne (events.js:96:13)
0|gladys | at Socket.emit (events.js:188:7)
0|gladys | at readableAddChunk (_stream_readable.js:176:18)
0|gladys | at Socket.Readable.push (_stream_readable.js:134:10)
0|gladys | at TCP.onread (net.js:547:20)

I can see only one possible issue :thinking:
You have rebuilt your index and your exec is not empty… Hmm

When you cloned your module in Gladys, did you go through the « Advanced » view, right?
And if so, what did you put in the « Slug » field?

I entered these values:

However, I just noticed that my module disappeared after a Gladys reboot ^^'.

Hello @aiaalm :slight_smile:.

What do you mean by updating?

If you’re talking about Gladys data, then yes. Otherwise, if you’re referring to the 3.7.3 update, no, I’m still waiting a bit for feedback before updating my devices :slight_smile:.

Oh! Unfortunately not, as I only have the info button ^^ and not the update button :slight_smile:
Thanks anyway @aiaalm ^^

@LepetitGeek do you have any idea then?

Here’s the behavior I’m seeing:
Module installation:
installationModule
Restart:
restartAfterInstall
Module disappeared:
afterRestart

What does it say in your logs?
Is it just me or did you click the button after the end of the installation of your module?
You say you are on 3.7.2? In this case, without seeing the logs, how do you know if Gladys has finished restarting?

1 Like

I didn’t actually click, but it gives that impression :slight_smile:.

I’m checking the logs on another monitor that tells me if it’s a restart or not :slight_smile:.

@aiaalm here are the logs:

0|gladys | House : checkUsersPresence
0|gladys | Cloning module hdmiCec…
0|gladys | Installing NPM dependencies for module hdmiCec
0|gladys | Dependencies installed for module hdmiCec
0|gladys | Module hdmiCec installed with success. Need reboot.
0|gladys | undefined
0|gladys | Warning: connect.session() MemoryStore is not
0|gladys | designed for a production environment, as it will leak
0|gladys | memory, and will not scale past a single process.
0|gladys | Warning: connect.session() MemoryStore is not
0|gladys | designed for a production environment, as it will leak
0|gladys | memory, and will not scale past a single process.
0|gladys | =======================================
0|gladys | WARNING: You currently have your default CORS settings configured to allow
0|gladys | all requests from all origins, with credentials. This may leave your app
0|gladys | open to attack by third-party sites! Consider making your origins setting
0|gladys | more restrictive or setting credentials to false, or else make certain that
0|gladys | none of your routes perform sensitive actions or reveal secure information.
0|gladys | =======================================
0|gladys | Gladys version : 3.7.2
0|gladys | Bootstrap is taking unusually long to execute its callback (2000 milliseconds).
0|gladys | Perhaps you forgot to call it? The callback is the first argument of the function, cb.
0|gladys | Gladys brain loaded with success !
0|gladys | Scheduled sunrise to 11/19/2017, 8:17:51 AM.
0|gladys | Scheduled alarm googleSynch, with id 2
0|gladys | Scheduled alarm check presence, with id 4
0|gladys | Scheduled sunset to 11/19/2017, 5:29:05 PM.
0|gladys | .-..-.
0|gladys | Sails <| .-..-.
0|gladys | v0.12.13 |\
0|gladys | /|.\
0|gladys | / || \
0|gladys | ,’ |’ \
0|gladys | .-‹ .-==|/_– ›
0|gladys | --'-------' 0|gladys | __---___--___---___--___---___--___ 0|gladys | ____---___--___---___--___---___--___-__ 0|gladys | Server lifted in /home/pi/gladys`
0|gladys | To see your app, visit http://localhost:8080
0|gladys | To shut down Sails, press + C at any time.
0|gladys | -------------------------------------------------------
0|gladys | :: Sun Nov 19 2017 16:51:00 GMT+0100 (CET)
0|gladys | Environment : production
0|gladys | Port : 8080
0|gladys | -------------------------------------------------------
0|gladys | NetworkScanner will scan network each 30 minutes.
0|gladys | New version of Gladys available : 3.7.3
0|gladys | Network scan completed. Found 7 devices.

And after the reboot the module is no longer present.

Yeah, I had a hard time seeing it because the image is so small :laughing:

Ok and did you check with FileZilla what’s happening in the hooks folder?

Regarding FileZilla, after installation, the folder is present, but after reboot, the folder has been deleted ^^

Thanks @LepetitGeek and @aiaalm for your help =D!

https://giphy.com/gifs/oKQHP89vJTUnm/html5

Okay, let’s proceed step by step. Try installing my module to see if it has the same behavior Device-HTTP

Installed → reboot → deleted

And in the log:

0|gladys | Cloning module Device-HTTP…
0|gladys | Installing NPM dependencies for module Device-HTTP
0|gladys | Dependencies installed for module Device-HTTP
0|gladys | Module Device-HTTP installed with success. Need reboot.
0|gladys | undefined
0|gladys | Warning: connect.session() MemoryStore is not
0|gladys | designed for a production environment, as it will leak
0|gladys | memory, and will not scale past a single process.
0|gladys | Warning: connect.session() MemoryStore is not
0|gladys | designed for a production environment, as it will leak
0|gladys | memory, and will not scale past a single process.
0|gladys | =======================================
0|gladys | WARNING: You currently have your default CORS settings configured to allow
0|gladys | all requests from all origins, with credentials. This may leave your app
0|gladys | open to attack by third-party sites! Consider making your origins setting
0|gladys | more restrictive or setting credentials to false, or else make certain that
0|gladys | none of your routes perform sensitive actions or reveal secure information.
0|gladys | =======================================
0|gladys | Gladys version : 3.7.2
0|gladys | Gladys brain loaded with success !
0|gladys | Scheduled sunrise to 11/19/2017, 8:17:51 AM.
0|gladys | Scheduled alarm googleSynch, with id 2
0|gladys | Scheduled alarm check presence, with id 4
0|gladys | Scheduled sunset to 11/19/2017, 5:29:05 PM.
0|gladys | .-..-.
0|gladys | Sails <| .-..-.
0|gladys | v0.12.13 ||
0|gladys | /|.
0|gladys | / |
0|gladys | ,’ |’
0|gladys | .-'.-==|/_–
0|gladys | --'-------' 0|gladys | __---___--___---___--___---___--___ 0|gladys | ____---___--___---___--___---___--___-__ 0|gladys | Server lifted in /home/pi/gladys0|gladys | To see your app, visit http://localhost:8080 0|gladys | To shut down Sails, press <CTRL> + C at any time. 0|gladys | ------------------------------------------------------- 0|gladys | :: Sun Nov 19 2017 17:09:47 GMT+0100 (CET) 0|gladys | Environment : production 0|gladys | Port : 8080 0|gladys | ------------------------------------------------------- 0|gladys | NetworkScanner will scan network each 30 minutes. 0|gladys | New version of Gladys available : 3.7.3 0|gladys | Network scan completed. Found 7 devices. 0|gladys | Socket disconnected, but session could not be loaded to pass to configured disconnect handler:sails.config.sockets.afterDisconnect()`. Will pass a fake, empty session as argument to lifecycle callback. Details:
0|gladys | Error: Session could not be loaded
0|gladys | at _createError (/home/pi/gladys/node_modules/sails/lib/hooks/session/index.js:31:19)
0|gladys | at Immediate. (/home/pi/gladys/node_modules/sails/lib/hooks/session/index.js:34:11)
0|gladys | at runCallback (timers.js:676:20)
0|gladys | at tryOnImmediate (timers.js:645:5)
0|gladys | at processImmediate [as _immediateCallback] (timers.js:617:5)
0|gladys | Event : create : new Event with code : alarm
0|gladys | Scenario : Trigger : New event : alarm
0|gladys | Scenario : Trigger : Found 2 launchers with code alarm.
0|gladys | Scenario : Trigger : Launcher condition verified.
0|gladys | Scenario : Trigger : Condition not verified.
0|gladys | Scenario : Trigger : Conditions verified, starting all actions.
0|gladys | Scenario : exec : Found 1 actions to execute.
0|gladys | Executing action « Execute a script »
0|gladys | House : checkUsersPresence

Are you in development mode?
What did you install Gladys on and how?
Have you tried installing modules from the store?

I installed Gladys on a raspberry 3b via the image provided by @pierre-gilles on this page:
https://gladysproject.com/fr/installation/

I then updated it a week ago to version 3.7.2 via this command /home/pi/rpi-update.sh
As indicated in the Gladys parameters.

The installation of store modules was working until now.

I just updated Gladys in case to 3.7.3.
I tried to install the mp3-player module and after reboot it is still present.

Despite the update, this has not resolved my problem: as soon as I want to install an external module, it disappears after reboot.

Another mystical error :joy:
Did you manually modify the Gladys core?

That really scares me xD

No, I haven’t made any changes ^^’

I don’t know if it’s related, but my weather widget isn’t working very well either since the beginning:

And when I talk on Telegram, I have to refresh the page to see the response.

Refresh:

Oh dear..
You must have had a problem from the start…
Can you start over with a clean installation? Like with another SD card?

For the weather station, are you using HTTPS?
And did you follow the entire installation tutorial?

I followed the installation tutorial that I shared earlier.
Could you provide me with a link? I’ll start from scratch and reset my SD card, I don’t have any other one ^^
Please
I’m not sure if I saw the tutorial for HTTPS though :confused: