Problem with scripting

Hi,
I’m trying to use scripting to read and act on the gpio output of my rpi.

First, I have to say it works with the rules (“power” change is detected when the gpio state is changed).

But it doesn’t when scripting. Here is my code

 import QtQuick 2.0
 import nymea 1.0
 
 Item {
    ThingState {
         id:monrelais
         thingId: "{43d036f4-b056-4d88-8cca-cc20d4aefcdb}" // GPIO 21 Relais
         stateName: "power"
         onValueChanged: {
             console.log("relais détecté");
          }
      }    
 }

Nothing appears in the console…

Am I doing something wrong?

Thanks! Laurent

I’ve just tried and indeed there seems to be a bug with the console output. If you create a new script it won’t pick it up. You can work around it with exiting the script editor and entering it again. Then it seems to work for me. I’ll look into the bug. Thanks for bringing it up.

Hope that helps.

Edit: Your script looks fine btw

Thanks for the quick answer.

I tried, but it doesn’t change anything. In fact, it doesn’t detect “power” change of the gpio at all (not only for the console) : I have tried with actions too, but they aren’t triggered either…

I’ve just tried with a Raspberry Pi gpio and your script, seems to work fine here… Not sure what could be wrong right now… Are you sure your thingId is correct?

Can you trigger actions by other means? for example

Component.onCompleted: someAction.execute(...)

would directly execute the action when deploying the script.

Hi,

OK, here is my new code. My Component.onCompleted executes the action. But the GPIO doesn’t when triggered. I checked the ThingsID (although it was “autocompleted”), and it is correct…

The timer doesn’t start either…

import QtQuick 2.0
import nymea 1.0

Item {
    id:root   
    property int counter: 0
    
    ThingAction {
        id:rafraichir
        thingId: "{59d7f9bc-bed9-43d6-94aa-a5aee1de2d79}" // Nuki Serrure Entree
        actionName: "refresh"
    }
    
    ThingAction {
        id:ouvrir
        thingId: "{59d7f9bc-bed9-43d6-94aa-a5aee1de2d79}" // Nuki Serrure Entree
        actionName: "unlatch"
    }
    
    ThingState {
        id:monrelais
        thingId: "{43d036f4-b056-4d88-8cca-cc20d4aefcdb}" // GPIO 21 Relais
        stateName: "power"
        onValueChanged: {
            console.log("relais détecté");
            ouvrir.execute({});
            root.counter = 1;
        }
    }
    
    Timer {
        id:timer
        interval: 1000
        repeat: false
        running: root.counter > 0
        onTriggered:{
       root.counter = 0;
      ouvrir.execute({})
         }    
        
    }
    Component.onCompleted:{
        ouvrir.execute({})
    }
  }

Give some more detail on the GPIO please. What thing class is it exactly? How are you triggering it?

Here are some screenshots.

It is triggered by a relay, acting as a switch. The relay actually works fine, and nymea detects it when using this rule :

It all looks fine… I’m stumbled… Does scripting work for you with other ThingStates or are all of them broken for you?

ThingState work for other equipment…

Hi,
I decided to suppress my gpio thing, rules, scripts, and recreate everything from scratch… and now, everything works as expected. I should have tried that earlier…
I must have done something wrong, and my config wasn’t ok anymore. Sorry for your time…

No worries, glad it works now for you.

Btw, I have already fixed the bug in the script editor where you’d need to exit it once after creating a new script for the console to work. Thanks again for bringing it up.