Blockly and lightsensor

Moderator: leecollings

Post Reply
LazyLizzard
Posts: 11
Joined: Wednesday 10 February 2016 20:41
Target OS: Linux
Domoticz version:
Location: Sweden
Contact:

Blockly and lightsensor

Post by LazyLizzard »

Hi!

I have a problem with my lightsensor and blockly. Can you please help me and see if I've done something wrong?

I have a "lightsensor" on 1-wire. It is a sensor that reports a voltage depending on the light. I want to use this sensor (Ljussensor Ute NV) to turn a dummy switch (Tända) on and off depending on the voltage. On a value below 200 I want it to be on, and over 200 I want it to be off. I'm going to have som more parameters in it later aswell, but for now I just want this simple thing to work. I have made a blockly like in the picture, but it wont work. When the value is above 200 there is no problem, the switch is off. But when the value drops below 200 it keeps going on and off at the same time. Have I done something wrong?

Maby a simple mistake by me, or is it something wrong in domoticz? I'm currently running v3.6595 built from source.

Any ideas?

//LazyLizzard
Attachments
ljussensor3.png
ljussensor3.png (31.36 KiB) Viewed 3012 times
ljussensor2.png
ljussensor2.png (26.08 KiB) Viewed 3012 times
ljussensor.png
ljussensor.png (14.85 KiB) Viewed 3012 times
kalinkamaen
Posts: 52
Joined: Sunday 04 January 2015 15:57
Target OS: Windows
Domoticz version: 2022.2
Location: Norway
Contact:

Re: Blockly and lightsensor

Post by kalinkamaen »

I cant see anythin g wrong. But try to set it up like this so you do not have the same number for on and off:

Image

You can also try 199 if thats better.
Windows 10, Domoticz 14784
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Blockly and lightsensor

Post by Toulon7559 »

Possible 2 reasons for the frequent switching.

1) Why did you include Tända=Off respectively Tända=Off in the IF-statements?
2) Checking in both Blockies just at the 200-level may cause a frequent switching, due to a dynamically fluctuating light-input.

Possibly around the '200'-level your 2 Blockies interact due to switching delays interfering with the check in the IF-lines.
Probably you intend to check whether it is necessary to switch, but the 'rude' method also works, of simply ordering a switch without check beforehand.
As improvement for 1) suggest to try in the first Blocky the simpler IF-statement
IF Ljussensor ute NV < 200
And in the second Blocky
IF Ljussensor ute NV > 200
To solve the dynamic aspect under 2) you can somewhat 'smooth' the new check by including a hysteresis like:
IF Ljussensor ute NV < 190
IF Ljussensor ute NV > 210
The practical thresholdvalues have to be found emperically.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
LazyLizzard
Posts: 11
Joined: Wednesday 10 February 2016 20:41
Target OS: Linux
Domoticz version:
Location: Sweden
Contact:

Re: Blockly and lightsensor

Post by LazyLizzard »

1) I like to have the Tända Off/On in the IF-statements for the blocky to check if it need to turn it on or off. But It's absolutley not needed for the function. I removed it for now just to get the main funcion of turning on and off to work.

2) It will absolutley cause frequent switching when the value in around 200, because it fluctuates. But the thing is that it keep turning on and off all the time even when the value have dropped. Like now for example the value is 56, but still keeps turning off and then on again.

I tried your examples, but unfortunatley it doesn't make any difference :( . Maby it just is some kind of a bug?

Thanks a lot for trying to help though!! :D
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Blockly and lightsensor

Post by tozzke »

the "problem" without that check, is that without them, the if statements keep triggering which asks quite a lot of Domoticz (check the log)
LazyLizzard
Posts: 11
Joined: Wednesday 10 February 2016 20:41
Target OS: Linux
Domoticz version:
Location: Sweden
Contact:

Re: Blockly and lightsensor

Post by LazyLizzard »

Exactly tozzke! Thats also a reason to why I want to have the check.
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Blockly and lightsensor

Post by PeGe »

Maybe a very silly question, but could it possibly be that the light source you turn on with "Tända" also affects (i.e. is seen by) your light sensor?

- It's too dark, so: "Tända" -> On
- Now it's too bright, so: "Tända" -> Off
- Damn, it turned dark again... "Tända" -> On

... and so on ... I think you get the point... 8-)

I suppose you have already eliminated such elementary root causes, but even the simple things can sometimes be easily overseen!

Furthermore; Avoiding unnecessary CPU and memory load, by checking the current state before acting, is always "good programming practice"!

/P-G
LazyLizzard
Posts: 11
Joined: Wednesday 10 February 2016 20:41
Target OS: Linux
Domoticz version:
Location: Sweden
Contact:

Re: Blockly and lightsensor

Post by LazyLizzard »

Thats not a silly question :) Sometimes you make really simple mistakes :D

Although that is not the problem this time. The sensor is outside where its not affected by anything else but the light outside.

Now when testning it also only controlls the dummy switch. Later the dummy will controll lighting inside.
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Blockly and lightsensor

Post by Toulon7559 »

What happens if you include a time-delay in the switching for a lightlevel < 200, by means of the middel block shown below?
It is a 'cosmetic' treatment, but with such delay you can suppress undue switching due to fluctuations of the light-input.
Blocky time-elements
Blocky time-elements
Knipsel170212.JPG (18.81 KiB) Viewed 2824 times
Sometimes it helps to apply a separate, auxiliary signal (a socalled 'semaphore' or 'flag'), instead of directly taking the result of the IF-statement using the signal-input. Reason: you clearly separate into slow and fast loops to avoid undesired, dynamic interaction, and the real switching is only performed at the conclusion of the decision process.
;-) You have a flagman, which after his own looking & thinking, by flagging generally guides the traffic (= your dimmer) ......

Possible (simplest) example layout for your case applying Blocky-components, incl. help of a delay:
IF level <200, DO "Flag = True for 5 minutes"
IF Flag = true, DO Dimmer = ON

Background:
level < 200 = raise the flag, level > 200 = do nothing, and wait until the flag drops
For realization of such layout you will have to add a userdefined variable Flag.
That addition may anyway be useful, because such variable is stored outside the script, and can be reused at the start of the script.
Last edited by Toulon7559 on Saturday 11 February 2017 10:16, edited 7 times in total.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Blockly and lightsensor

Post by PeGe »

One thing that puzzles me when viewing your switch history listing, is the fact that both the ON and OFF transitions occur at the very same second. That "should" be impossible, according to the logic you have defined.

The script will only run once per second, and when the first 'If' expression evaluates as TRUE, it should never even attempt to evaluate the 'Else if' during the same excution cycle. Consequently, it would be practically impossible for the script to take both of the actions at the exact same time.

You wouldn't happen to have another (similar) copy of that script activated simultaneously? When testing new stuff myself, I often save multiple versions of my work, so it wouldn't be a situation totally unheard of... :oops:

/P-G
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Blockly and lightsensor

Post by tozzke »

PeGe wrote:One thing that puzzles me when viewing your switch history listing, is the fact that both the ON and OFF transitions occur at the very same second. That "should" be impossible, according to the logic you have defined.

The script will only run once per second, and when the first 'If' expression evaluates as TRUE, it should never even attempt to evaluate[/b] the 'Else if' [/b]during the same excution cycle. Consequently, it would be practically impossible for the script to take both of the actions at the exact same time.

You wouldn't happen to have another (similar) copy of that script activated simultaneously? When testing new stuff myself, I often save multiple versions of my work, so it wouldn't be a situation totally unheard of... :oops:

/P-G
You might think that but it does @ Domoticz :)
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Blockly and lightsensor

Post by PeGe »

tozzke wrote:You might think that but it does @ Domoticz :)
Seriously? :shock:

Now, I don't intend to hijack this thread, but I would truly consider that behavior to be a serious bug, as "ESLE" would have completely lost its meaning!

In my every day life, I'd always use "else if" statements in such a sequence that the most probable condition to evaluate as TRUE comes on top, continuing down depending on "what the odds are". If you have a sequence of let's say 20 "else if" sections and you'd get a hit already in the second statement, a system SHOULD NEVER be bothered with processing the remaining ones. After all, that's the whole basic idea with "else if" vs just multiple consecutive "if"s.

Disappointing...

/P-G
jensc
Posts: 41
Joined: Saturday 12 March 2016 1:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.3
Location: Saint Helens, Oregon, USA
Contact:

Re: Blockly and lightsensor

Post by jensc »

Interesting point. Bug, yes?
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Blockly and lightsensor

Post by Toulon7559 »

This thread raises the question:
why not an ELSE or ELSIF in Blocky?
To make unambiguous decisions after a check.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests