Page 1 of 1

BH1750 - heating status

Posted: 13 Nov 2018, 20:12
by TungstenE2
Hi all,

I have BH1750 installed on Wemos D1 mini and attached to my central heating in the basement.
There is a small red status LED, where I would like to catch the status.

In normal mode the LED is turned on while heating. Lux = 3-4
If heating is off Lux = 0

In case of failure the LED is blinking, but not very fast.

I would like to create a rule or similar in order to get a notice via FHEM and Telegram that the heating is in failure mode.

So how best to catch the blinking? Using a counter?
BH1750.PNG
BH1750.PNG (20.84 KiB) Viewed 9255 times
thx

Re: BH1750 - heating status

Posted: 13 Nov 2018, 20:16
by grovkillen
You could use a timer and see it the change is still there after a second. See the rules section for the long press example.

Re: BH1750 - heating status

Posted: 14 Nov 2018, 08:38
by TungstenE2
ok, thx. So I will try to setup a dummy switch which will be set by a rule if lux >2. This will indicated the LED is on.

But I have a question on the timer and long press. How does the sample rule distinguish between short press and still pressed?
Is this because the timer was triggered and when the rule is checking the status is back to 0?
So I need to find the right duration of the LED blinking and change 'timerSet,1,1' accordingly?

Code: Select all

on Button#State=1 do
  timerSet,1,1
endon

on rules#timer=1 do
 if [Button#State]=0
  //Action if button is short pressed
 else
  //Action if button is still pressed
 endif
endon

Re: BH1750 - heating status

Posted: 14 Nov 2018, 09:47
by toffel969
TungstenE2 wrote: 14 Nov 2018, 08:38 ok, thx. So I will try to setup a dummy switch which will be set by a rule if lux >2. This will indicated the LED is on.

But I have a question on the timer and long press. How does the sample rule distinguish between short press and still pressed?
Is this because the timer was triggered and when the rule is checking the status is back to 0?
So I need to find the right duration of the LED blinking and change 'timerSet,1,1' accordingly?

Code: Select all

on Button#State=1 do
  timerSet,1,1
endon

on rules#timer=1 do
 if [Button#State]=0
  //Action if button is short pressed
 else
  //Action if button is still pressed
 endif
endon
Hi

I think you should use a different sensor. In my experiene the BH1750 is just to slow to catch blinking LED's. Its a great sensor for ambient light. Just not very fast and the I2C protocoll causes overhead. All you really need is a digital output (LED on or not)

check out https://www.mysensors.org/build/pulse_power

for some inspirtation

Re: BH1750 - heating status

Posted: 15 Nov 2018, 18:18
by TungstenE2
setup following rules:

Code: Select all

On System#Boot do
  TaskValueSet 2,1,0
  TaskValueSet 2,2,0
  endon

// reset HeatingError after 90Sek

on Heizung#Lux=0 do
  timerSet,2,90
endon

on rules#timer=2 do
  TaskValueSet 2,2,0
endon  


// set HeatingLED

on Heizung#Lux>20 do
  TaskValueSet 2,1,1
endon

on Heizung#Lux<5 do
  TaskValueSet 2,1,0
endon
  
// check if LED is blinking by checking Lux via Timer1   
  
on Heizung#Lux>2 do
  timerSet,1,1
endon

on rules#timer=1 do
 if [Heizung#Lux]<2
     TaskValueSet 2,2,1
 else
   TaskValueSet 2,2,0
   endif
endon
In general it seems to be working. Only problem is that when heating LED in normal mode is turned off, this is recognized by the rule and the error status is set. I am trying to fix this with timer 2, but seems like this is not working.

Any idea how to fix this?
BH1750-2.PNG
BH1750-2.PNG (40.24 KiB) Viewed 9197 times

Re: BH1750 - heating status

Posted: 15 Nov 2018, 18:35
by grovkillen
You should use a task run command after the TaskValueSet for it to trigger the events for those values

Re: BH1750 - heating status

Posted: 16 Nov 2018, 07:23
by TungstenE2
can you provide me with the syntax of 'task run'? do not find a sample in the rules wiki.

Re: BH1750 - heating status

Posted: 16 Nov 2018, 08:22
by grovkillen
TaskRun,<task number>

Re: BH1750 - heating status

Posted: 16 Nov 2018, 10:07
by TungstenE2
thx, included it, but seems not to be working.

Code: Select all

On System#Boot do
  TaskValueSet 2,1,0
  TaskValueSet 2,2,0
  endon

// reset HeatingError after 90Sek

on Heizung#Lux=0 do
  timerSet,2,90
endon

on rules#timer=2 do
  TaskValueSet 2,2,0
TaskRun,2
endon  


// set HeatingLED

on Heizung#Lux>20 do
  TaskValueSet 2,1,1
endon

on Heizung#Lux<5 do
  TaskValueSet 2,1,0
endon
  
// check if LED is blinking by checking Lux via Timer1   
  
on Heizung#Lux>2 do
  timerSet,1,1
endon

on rules#timer=1 do
 if [Heizung#Lux]<2
     TaskValueSet 2,2,1
 else
   TaskValueSet 2,2,0
   endif
endon

Re: BH1750 - heating status

Posted: 16 Nov 2018, 10:33
by grovkillen
Sorry I must have misunderstood you. I suggest you use this rule instead:

Code: Select all

On System#Boot do
  TaskValueSet 2,1,0
  TaskValueSet 2,2,0
endon

// reset HeatingError after 90Sek

on Heizung#Lux=0 do
  timerSet,2,90
endon

on rules#timer=2 do
  TaskValueSet 2,2,0
endon  


// set HeatingLED

on Heizung#Lux do
 if [Heizung#Lux]>20
  TaskValueSet,2,1,1
 endif
 if [Heizung#Lux]<5
   TaskValueSet,2,1,0
  endif
  if [Heizung#Lux]>2 do
   timerSet,1,1
  endif
endon

on rules#timer=1 do
 if [Heizung#Lux]<2
     TaskValueSet 2,2,1
 else
   TaskValueSet 2,2,0
   endif
endon
May work?

Re: BH1750 - heating status

Posted: 16 Nov 2018, 11:49
by TungstenE2
hm, still not working as expected.

If heating is on, Lux is up to 24 and HeatingLED is 1 and HeatingError is 0.
If heating is off, Lux is 0 and HeatingLED is 0 but HeatingError is 1 and is not reset.
This is triggered as the tigger sees the LED is switching from 1to 0, but this should be reset, as it is not back to 1.

Blinking was recognized as expected, but normal mode when heating is off is not.

Dont know how to solve this...
BH1750-3.PNG
BH1750-3.PNG (28.26 KiB) Viewed 9162 times

Re: BH1750 - heating status

Posted: 16 Nov 2018, 11:59
by grovkillen
Move this part into the Heizung#Lux chunk:

Code: Select all

on Heizung#Lux=0 do
  timerSet,2,90
endon
Just as the other if statements.

Re: BH1750 - heating status

Posted: 16 Nov 2018, 12:50
by TungstenE2
moved it, but still the same result

Code: Select all

On System#Boot do
  TaskValueSet 2,1,0
  TaskValueSet 2,2,0
endon

  
on Heizung#Lux do
 if [Heizung#Lux]>20
  TaskValueSet,2,1,1
 endif
 if [Heizung#Lux]<5
   TaskValueSet,2,1,0
 endif
 if [Heizung#Lux]>2 do
   timerSet,1,1
 endif
 if [Heizung#Lux]=0 do
   timerSet,2,30
 endif
endon

// set HeatingLED
on rules#timer=1 do
 if [Heizung#Lux]<2
     TaskValueSet 2,2,1
 else
   TaskValueSet 2,2,0
   endif
endon

// reset HeatingError
on rules#timer=2 do
  TaskValueSet 2,2,0
endon

Re: BH1750 - heating status

Posted: 16 Nov 2018, 13:58
by grovkillen
Move this part to the top of the event chunk.

Code: Select all

if [Heizung#Lux]=0 do
   timerSet,2,30
 endif
If not it'll never trigger since it's also "<5"

Re: BH1750 - heating status

Posted: 16 Nov 2018, 15:02
by TungstenE2
done, but still the same...

Code: Select all

On System#Boot do
  TaskValueSet 2,1,0
  TaskValueSet 2,2,0
endon

  
on Heizung#Lux do
 if [Heizung#Lux]=0 do
   timerSet,2,30
 endif
 if [Heizung#Lux]>20
  TaskValueSet,2,1,1
 endif
 if [Heizung#Lux]<5
   TaskValueSet,2,1,0
 endif
 if [Heizung#Lux]>2 do
   timerSet,1,1
 endif
endon

// set HeatingLED
on rules#timer=1 do
 if [Heizung#Lux]<2
     TaskValueSet 2,2,1
 else
   TaskValueSet 2,2,0
   endif
endon

// reset HeatingError
on rules#timer=2 do
  TaskValueSet 2,2,0
endon