Blockly examples

Moderator: leecollings

ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Blockly examples

Post by ThinkPad »

I am not going to remake your event, that way you don't learn anything from it.

Some hints:
- You need to check every device/switch separately, see also below
- You are not using the 'AND' in the correct way. Use it like this: [lamp1 = On] AND [lamp2 = On].... Not like: lamp1 AND lamp2 = On... won't work
- You are now checking for the EXACT moment of sunset/sunrise. So one minute before/after sunset/sunrise the condition isn't valid anymore

Check the previous pages of this topic for inspiration/guidelines
I am not active on this forum anymore.
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

ThinkPad wrote:I am not going to remake your event, that way you don't learn anything from it.

Some hints:
- You need to check every device/switch separately, see also below
- You are not using the 'AND' in the correct way. Use it like this: [lamp1 = On] AND [lamp2 = On].... Not like: lamp1 AND lamp2 = On... won't work
- You are now checking for the EXACT moment of sunset/sunrise. So one minute before/after sunset/sunrise the condition isn't valid anymore

Check the previous pages of this topic for inspiration/guidelines
more like this :
Image

I'am busy with the : zon op (licht), zon onder (donker) ( Sunrise : light , Sunset Dark) blocky , first i'am reading a lot about the possibilities .
should i use Json script (as found on tweakers.net), or just use al blocky example

But how is it possible to create this blocky to learn : when whe arrive at home the light levels up ( %) ?
It's nice to be important, but it's more important to be nice
Scooter ;)
floris74
Posts: 75
Joined: Sunday 30 November 2014 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hoorn, Netherlands
Contact:

Re: Blockly examples

Post by floris74 »

leby wrote:Think you need a little bit of lua.. I use a lua script to know how long time have passed since my motion sensor was breached, guess you can exchange the motion sensor with a dummy switch that is turned on when you have >3500 lux.

1) Create o dummy switch
2) Create one user variable named "Dummy switch time" give it a start value of say '1'
3) Make a blockly event that turns on the dummy switch when the sensor is >3500 lux and off if sensor is <3400
4) Add the script below to the script folder
5) now you can build your event and trigger on the value of the variable "Dummy switch time" (for example if its more than 120 or what ever)

Code: Select all

commandArray = {}

	t1 = os.time()
	t2 = uservariables['Dummy switch time']
	r0 = t1-t2

	commandArray['Variable:Timewithmorethan3500'] = tostring(r0)
	print('Timewithmorethan3500  ' .. r0)
return commandArray
Think this i principle should work with your scenario..
Thanks. i hope i can use this the next days..

Floris
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

Could anybody help me , i'am getting this error ( after update to Beta 2385)

Code: Select all

2015-04-28 10:46:00.337 Hardware Monitor: Fetching data (System sensors)
2015-04-28 10:46:00.341 Error: Lua script error (Blockly), Name: Lamp_1 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: ')' expected near 'comparevariable'
2015-04-28 10:46:00.341 Error: Lua script error (Blockly), Name: Lamp_2 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: ')' expected near 'comparevariable'
It's nice to be important, but it's more important to be nice
Scooter ;)
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

thecosmicgate wrote:Could anybody help me , i'am getting this error ( after update to Beta 2385)

Code: Select all

2015-04-28 10:46:00.337 Hardware Monitor: Fetching data (System sensors)
2015-04-28 10:46:00.341 Error: Lua script error (Blockly), Name: Lamp_1 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: ')' expected near 'comparevariable'
2015-04-28 10:46:00.341 Error: Lua script error (Blockly), Name: Lamp_2 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: ')' expected near 'comparevariable'
Solved after delete the event. First i couldn't remove this event (i thought) but it looks like there were serveral "lamp" events , i had to push "delete event" 4 times and everything seems to be ok for now.

Still looking for the self learning event as discribed
It's nice to be important, but it's more important to be nice
Scooter ;)
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

ThinkPad wrote:Event to control virtual switch 'IsDark'
Image

You can use this event to control a virtual switch, called 'IsDark'. You can then use the 'IsDark' in your other events to check if it is dark outside.
You may think, why not use a simple timer to turn this virtual switch on/off?

The timer will only switch at the configured moment. But if that moment is missed because the Pi had a power failure for example, your lights will never turn on after the Pi has booted again, because Domoticz won't check if the switch has turned on if the configured switch time has passed.

The event is different in this, because it will ALWAYS check the conditions and thus works always. If you boot your Pi in the middle of the night (after it has been off for the whole day) and the virtual switch is still in the 'day' setting, the event will turn it to the correct setting (=IsDark is on).


P.S. The 'OR' in the 'ELSE IF' line is correct. Domoticz validates till 23:59, at 0:00 a new day starts. Therefore by using 'AND' the condition will never become true.
I complete "copied" the blockly :
Image

with virtual switch:
Image

But the switch doesn't flip from off to on , if i want to press the switch manually using the web interface it doesn't work or change status .

What's wrong ?
It's nice to be important, but it's more important to be nice
Scooter ;)
User avatar
StanHD
Posts: 347
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Re: Blockly examples

Post by StanHD »

Hi, does it change state if you temporarily "Reverse" the logic for testing? (Off to On / On to Off etc)
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

StanHD wrote:Hi, does it change state if you temporarily "Reverse" the logic for testing? (Off to On / On to Off etc)
Done :
Image


The switch itself doesn't flip :(

i googled around and found this

Image
witch seems to work okay (except the variable ) because i don't know why to use this :oops:
It's nice to be important, but it's more important to be nice
Scooter ;)
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Blockly examples

Post by ThinkPad »

I used a normal on/off switch for it, not the dusk/dawn type you are using. Try that ;) It's only a visual matter, it's about the result right ;) ?
I am not active on this forum anymore.
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

thecosmicgate wrote:
ThinkPad wrote:I am not going to remake your event, that way you don't learn anything from it.

Some hints:
- You need to check every device/switch separately, see also below
- You are not using the 'AND' in the correct way. Use it like this: [lamp1 = On] AND [lamp2 = On].... Not like: lamp1 AND lamp2 = On... won't work
- You are now checking for the EXACT moment of sunset/sunrise. So one minute before/after sunset/sunrise the condition isn't valid anymore

Check the previous pages of this topic for inspiration/guidelines
more like this :
Image

I'am busy with the : zon op (licht), zon onder (donker) ( Sunrise : light , Sunset Dark) blocky , first i'am reading a lot about the possibilities .
should i use Json script (as found on tweakers.net), or just use al blocky example

But how is it possible to create this blocky to learn : when whe arrive at home the light levels up ( %) ?
now made the combination with the : is dark switch :
Image

Could somebody tell me if this is okay and working
It's nice to be important, but it's more important to be nice
Scooter ;)
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Blockly examples

Post by leby »

you can't have the or between two switches, need to set up two separate comparisons. (the two phones)
/lennart
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

leby wrote:you can't have the or between two switches, need to set up two separate comparisons. (the two phones)
Maybe better to make a special (iemand thuis / anybody home) switch ?
I don't exactely understand understand / know how to (easy) make to separate comparisons in this blockly Image
It's nice to be important, but it's more important to be nice
Scooter ;)
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Blockly examples

Post by ThinkPad »

A 'SomeoneHome' switch is easier, i also use it that way: http://www.domoticz.com/forum/viewtopic ... 521#p27521
I am not active on this forum anymore.
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

ThinkPad wrote:A 'SomeoneHome' switch is easier, i also use it that way: http://www.domoticz.com/forum/viewtopic ... 521#p27521
Done :)
But could you maybe explain a little bit about : variable that you use in the Switch on lights when we are home, and it is getting dark and Turn on lights when we arrive home and it is dark outside blocky you use .
I tried the wiki but don't understand exactely what this variable do and mean .
It's nice to be important, but it's more important to be nice
Scooter ;)
User avatar
thecosmicgate
Posts: 188
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Re: Blockly examples

Post by thecosmicgate »

thecosmicgate wrote:
ThinkPad wrote:A 'SomeoneHome' switch is easier, i also use it that way: http://www.domoticz.com/forum/viewtopic ... 521#p27521
Done :)
But could you maybe explain a little bit about : variable that you use in the Switch on lights when we are home, and it is getting dark and Turn on lights when we arrive home and it is dark outside blocky you use .
I tried the wiki but don't understand exactely what this variable do and mean .
Can anybody tell or help me a little bit more about the variable option ?
It's nice to be important, but it's more important to be nice
Scooter ;)
floris74
Posts: 75
Joined: Sunday 30 November 2014 8:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hoorn, Netherlands
Contact:

Re: Blockly examples

Post by floris74 »

floris74 wrote:
leby wrote:Think you need a little bit of lua.. I use a lua script to know how long time have passed since my motion sensor was breached, guess you can exchange the motion sensor with a dummy switch that is turned on when you have >3500 lux.

1) Create o dummy switch
2) Create one user variable named "Dummy switch time" give it a start value of say '1'
3) Make a blockly event that turns on the dummy switch when the sensor is >3500 lux and off if sensor is <3400
4) Add the script below to the script folder
5) now you can build your event and trigger on the value of the variable "Dummy switch time" (for example if its more than 120 or what ever)

Code: Select all

commandArray = {}

	t1 = os.time()
	t2 = uservariables['Dummy switch time']
	r0 = t1-t2

	commandArray['Variable:Timewithmorethan3500'] = tostring(r0)
	print('Timewithmorethan3500  ' .. r0)
return commandArray
Think this i principle should work with your scenario..
Thanks. i hope i can use this the next days..

Floris

Sorry, but i get lost at step 3. do i need to edit the lua? what kind of lua must it be?

tnx Floris

edit: i have a variable named screen sun (must be switched to 1 after 2 minutes of sun(30000>lux)) and screen cloud (must be switched to 1 after 15 min of beiing cloud (29000 < lux))
i cant upload a picture?
h143
Posts: 27
Joined: Tuesday 28 October 2014 22:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly examples

Post by h143 »

I have the follow blocky to control the humidity in the batroom
Blocky badkamer.jpg
Blocky badkamer.jpg (106.31 KiB) Viewed 8789 times
when the receiver from the ventilator miss the signal domoticz send it 5 seconds later again

i have make the variable in the blocky so i can always overule by the manual switch
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Blockly examples

Post by ThinkPad »

Looks good :)

Is the sensor updating fast enough? So you don't have your shower steaming for 5 minutes until the fan turns on?
I am not active on this forum anymore.
RichardBokker
Posts: 39
Joined: Thursday 09 April 2015 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: Netherlands
Contact:

Re: Blockly examples

Post by RichardBokker »

Why is this not working?

i want to detect MaxValue of Usage (yes i know, i can see 24h log), but i want it in a variable.
So i made an UserVariable "VermogenMax" integer. I i'm checking if VermogenMax is smaller then the usage, if so, then save the actual value in VermogenMax. But the value stay's 0.

i tried to use a dummy device, type Usage, is also not working :?:

Another question, how can i add VermogenMax (uservariable) to a roomplan? In order to show the value on frontpage.html.
Attachments
MaxDetectie.png
MaxDetectie.png (16.26 KiB) Viewed 8760 times
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Blockly examples

Post by ThinkPad »

thecosmicgate wrote:
ThinkPad wrote:A 'SomeoneHome' switch is easier, i also use it that way: http://www.domoticz.com/forum/viewtopic ... 521#p27521
Done :)
But could you maybe explain a little bit about : variable that you use in the Switch on lights when we are home, and it is getting dark and Turn on lights when we arrive home and it is dark outside blocky you use .
I tried the wiki but don't understand exactely what this variable do and mean .
Sorry, didn't see your post.

The var is so that when you turn the lights off, they don't turn on directly again (because the conditions are then all valid again). I reset the var at 00:01 or so i thought.
But i don't use that Blockly anymore, i now use the ABST-604 dusk/dawn sensor together with this script.
I am not active on this forum anymore.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest