Script with Blocky control light by montion sensor

  • Platform information:
    • Hardware: Rpi 4 4gb_
    • OS: Raspberry linux
    • openHAB version: _Openhab 3.3.0

Hi,

I’ve got my first script with blocky.
What I have to do is control a Switch (connected to a light) with a motion sensor.

I will next upgrade my system adding a control by the level of lx (activate the function under a level of lux).

That’s what I arrived… no need to say that it doesn’t work… :slight_smile:
So what I’m missing?

How does this rule get triggered? It seems odd to test the state of the motion sensor if it was the motion sensor that triggered the rule in the first place. You can make it so the rule only triggers when the sensor goes to ON which would be a pretty standard motion sensor timer kind of approach. With this kind of trigger, you’ll already know that the motion sensor is ON and there’s no need to test for it in the script action.

I would recommend using more meaningful Item names. “BasementHallMotionSensor” is a lot more meaningful to you the human (who is the one who needs to read and understand your OH rules and other configs in the future) than “ZWaveNode002ZWA005Motionlightandtemperaturesensor_Motion”. Especially if you have a bunch of these devices in your system. By the time it gets to be represented by Items, the fact that it’s ZWave and specifics like that do not and should not matter.

I wouldn’t go and change your existing Item names now, particularly if you’ve a lot of them and they are used by name in a bunch of places (rules, widgets, etc). But in the future, think about Item names more from the perspective of telling other members of the household what it is. You wouldn’t say to your kids “go turn off ZWaveNode003FGS224FibaroDoubleSmartModule_Switch1”, you would say “go turn off the basement hallways light”. So name the Items that way. It will make your rules and configs much easier for you to understand and maintain in the long run.

Make this a rule condition.

Note, a rule includes a lot outside of the Script Action. So while it’s important to have a screen shot of the Blockly, it’s very helpful to see the rest of the rule too. So go to the “Code” tab and paste in everything you find there into your forum posts so we can all see a fuller picture of the rule. Use code fences:

```
code goes here
```

To diagnose what’s wrong we’ll need to see the full rule, snippets of the events log that should trigger the rule and see whether or not the switches go OFF 30 seconds later.

It would also be helpful to add some logging to show the rule gets triggered, and what parts of the rule get executed. Those will appear in openhab.log.

After you comment I understood my 1st error…
I’ve haven’t given a “trigger condition” (or… i thinked that just scripting the condition is enogh… my bad!).

So I re-write the rule to have the “trigger condition” - Motion Sensor ON.
It work… yehee!

Now, the condition about the light… it seems to work… but I have to regolate the sensor to send more report about it…

I will try tomorrw the “reschedule” function… just to understand if I can mantain the light on when i’m in the corridor.

For the moment, is enogh sorry for bothering :slight_smile: my newbiness is infinite!