[solved for FHEM] Avoid of sending first data from dummy-device to controller after reboot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

[solved for FHEM] Avoid of sending first data from dummy-device to controller after reboot

#1 Post by alabama » 20 Nov 2018, 11:58

After my success with help of @dynamicdave of my soil moisture measurement system I have one more problem. My code shows (so I hope) the procedure:
- One analog input device is read every 1/2 hour. To do this physical device is switched on by GPIO12 (by use of a transstor - it's not important for my problem)
- The value of the analog input is copied to the dummy device 11. This dummy device is sending its value on change to controller 1.

Everything works fine while normal operation. But every time the WeMos is booting the value of the dummy device (which is 0 at this stage) is send to the controller before something is copied from the analog device. I had tried many different versions to avoid this "0" in my log, but nothing helps. It seems that the very first event is set something to the dummy can't be avoid. Is this true or is there a failure from me?

(Hope one can understand what I want to say....)

Code: Select all

On System#Boot do
 timerSet,1,0
 TaskValueSet,12,1,0 // Set vars#activation = 0
 TaskValueSet,12,2,1 // Set vars#sent = 1
 timerSet,2,10 // Start first automatic cycle after 10 sec.
 timerSet,8,60 // Set Timer 8 for notify by mail in 60 seconds
endOn

On Clock#Time=All,1:50 do // Reboot every night
  timerSet,7,55
Endon
on Rules#Timer=7 do
 WifiDisconnect
 Reboot
endOn

On Rules#Timer=8 do // Send Mail after Boot
 notify 1, "WEMOS-2: System gestartet"
endOn

On activate do // Manual start per browser or FHEM
 GPIO,12,1 // Set GPIO12(D6)=1 (Turn on the transistor)
 TaskValueSet,12,1,1 // Set vars#activation = 1
 TaskValueSet,12,2,0 // Set vars#sent = 0
 timerSet,1,6
 timerSet,2,1800 // Restart cycle every 1/2 hour
endOn

On Rules#timer=2 do // Automatic cycle by internal timer
 GPIO,12,1 // Set GPIO12(D6)=1 (Turn on the transistor)
 TaskValueSet,12,1,1 // Set vars#activation = 1
 TaskValueSet,12,2,0 // Set vars#sent = 0
 timerSet,1,6
 timerSet,2,1800 // Restart cycle every 1/2 hour
endOn

On paw#value do
 If [vars#activation]>0 and [vars#sent]=0
 TaskValueSet,11,1,[paw#value] // Write data from analog input to dummy and send this to controller 1 (FHEM)
 TaskValueSet,12,2,1 // Set vars#sent = 1
 endIf
 endOn

On Rules#timer=1 do
 GPIO,12,0 //Set GPIO(D6)=0 (Turn off the transistor)
 TaskValueSet,12,1,0 // Set vars#activation = 0
 endOn

Last edited by alabama on 21 Nov 2018, 12:08, edited 2 times in total.

Tecumseh
Normal user
Posts: 28
Joined: 30 Sep 2016, 09:42

Re: Avoid of sending first data from dummy-device to controller after reboot

#2 Post by Tecumseh » 20 Nov 2018, 12:11

You could disable sent to controller on the dummy device and use the publish commend in your rules. That way you make sure it is only sent after an update.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: Avoid of sending first data from dummy-device to controller after reboot

#3 Post by alabama » 20 Nov 2018, 12:15

So easy? :oops:
I thought that the publish command don't works with FHEM as controller? Okay, I'll try it when I'm at home.

Thank you.

Tecumseh
Normal user
Posts: 28
Joined: 30 Sep 2016, 09:42

Re: Avoid of sending first data from dummy-device to controller after reboot

#4 Post by Tecumseh » 20 Nov 2018, 12:28

Sorry I was thinking you needed MQTT publish, not sure what or how things get published to FHEM

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: Avoid of sending first data from dummy-device to controller after reboot

#5 Post by alabama » 20 Nov 2018, 12:33

But I think your tip is right. As far as I remember I can use MQTT together with FHEM. I only want to avoid one more system this time.

User avatar
dynamicdave
Normal user
Posts: 147
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Avoid of sending first data from dummy-device to controller after reboot

#6 Post by dynamicdave » 20 Nov 2018, 12:48

Hi,
Just noticed in one of your rules the named-variable 'var'.
You might run into trouble using this becuase as from November 2018 release of EASY Easy Mega, 'var' is a reserved command in rules.
You might want to change it to 'variable' or 'vars'.

Here's what I was told...
- - - -
The problem with your rule is that [Var#n] is a reserved command that retrieves the system variable %Vn%.

Wiki should be updated with this new commands and system variables.
- - - -

On paw#value do
If [var#activation]>0 and [var#sent]=0
TaskValueSet,11,1,[paw#value] // Write data from analog input to dummy and send this to controller 1 (FHEM)
TaskValueSet,12,2,1 // Set var#sent = 1
endIf
endOn

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: Avoid of sending first data from dummy-device to controller after reboot

#7 Post by alabama » 20 Nov 2018, 14:34

Thank you, I'll change it.

EDIT: I also changed it in the code in the post above so that hopefull nobody copy this failure.

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: Avoid of sending first data from dummy-device to controller after reboot

#8 Post by alabama » 21 Nov 2018, 12:07

The solution is to use SendToHTTP instead of publish. In my specific case I have for the test the dummy device ESP_Test defined in FHEM, With the following SendToHTTP in my rules it works fine to send the value direct to FHEM

Code: Select all

On paw#value do
 If [vars#activation]>0 and [vars#sent]=0
 SendToHTTP 192.168.xxx.xxx,8083,/fhem?cmd=setreading%20ESP_Test%20Testwert%20[paw#value]
  TaskValueSet,12,2,1 //Set vars#sent = 1
 endIf
 endOn

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests