Blockly Events in specific days!

Moderator: leecollings

Post Reply
juankar
Posts: 223
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Blockly Events in specific days!

Post by juankar »

Hello
I want that a event wrote with blockly run just in some days of the week. It looks like very easy: an If for check day of week.... but...
Snap1.png
Snap1.png (32.27 KiB) Viewed 2453 times
I save it as device type. What I want is
if Day is not Saturday {
IF (cocina-mov = on and cocina-lux < 10) THEN cocina = ON
ELSE IF (cocina-mov = off and cocina = on) THEN light = OFF
}

cocina-mov is a PIR an cocina-lux is for metering lux. cocina is a light
I think the logic is OK, but when movement is detected and light is <10 and it's not saturday controller doesn't send any command

I think the script is correct. It Is saved as device and cocina-mov is involved so it must be triggered when cocina-mov changes, but it's not triggered when cocina-mov changes.

If a delete the checking of weekday the script works fine.

Then I made a change and wrote this blocky, also saved as device
Snap2.png
Snap2.png (48.06 KiB) Viewed 2449 times
Logic now is
if (Day is not Saturday and cocina-mov has changed){
write to log cocina-mov and cocina-lux
IF (cocina-mov = on and cocina-lux < 10) THEN cocina = ON
ELSE IF (cocina-mov = off and cocina = on) THEN light = OFF
}
When I go into the room, PIR detects me and I get in log that cocina-mov is ON and cocina-lux is 0, but controller sends an OFF command instead an ON.
It Is also saved as device and cocina-mov is involved in the first IF sentence, now script is triggered but it sends the wrong command, an OFF, it evaluates to false (cocina-mov = on and cocina-lux < 10) althoug it writes in log cocina-mov is ON and cocina-lux is 0.

Why it doesn't work?
Thanks
juankar
Posts: 223
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Re: Blockly Events in specific days!

Post by juankar »

I've made more tests with blockly scripts and i've found that blocky works in a strange way
I see that nested IF doesn't work properly and the script is triggered for every device used in an IF sentence!
And time triggering doesn't work with blockly (it works fine with lua)
Try this example. It uses 3 switches (virtual swtiches) Int0, Int1, Int2
If you turn On Int0 then int1 must change its status (if Off it goes to On and viceversa).
If you turn Off Int0 then int1 and Int2 must goes to Off.

If saved as time triggered event it doesn't work
If saved as device triggered event:
it is not triggered when Int0 goes to OFF, just trigger when goes to ON
If you turn switch Int1 the event is triggered, and if it's ON you cannot turn it OFF
So, how works blockly?
Snap3.png
Snap3.png (33.89 KiB) Viewed 2427 times
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Blockly Events in specific days!

Post by Egregius »

I think you far better of learning one of the scripting languages rather than using blockly.
I use PHP for everything. Like 'day of week' is just standaard stuff there:

Code: Select all

if(date('N')==3) echo "today it's Wednesday";
elseif(date('N')==5) echo "today it's Friday";
Simple, isn't it?
juankar
Posts: 223
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Re: Blockly Events in specific days!

Post by juankar »

Of course, Lua is a very good language for build scripts, it's connected with Domoticz and its easy and well documented as PHP or Perl does.
But Blockly is good as script editor (it's not a language) and it makes confortable to create customized script. The problem is that it's very restricted (the version used in Domoticz). I know that scripts wrote with Blockly can be translated into Lua, PHP, JavaScript.... I think this is a way to enhance Domoticz: full blockly integrated in Domoticz and used as a visual editor for creating Lua scripts.
https://developers.google.com/blockly/
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest