Controlling a Nexa Switch based on windspeed

Questions and comments specific to a particular plugin should go here.
Post Reply
anderspnilsson
Posts: 5
Joined: Wed Nov 18, 2015 9:45 pm

Controlling a Nexa Switch based on windspeed

Post by anderspnilsson » Wed Nov 18, 2015 9:55 pm

Hi,

I have a Gardena watering system and would like to prevent watering when its to windy (will be watering my neighbours house then ;-)).
In order to prevent watering when its windy I have used the input on the Garden computer for the rain sensor through a relay controlled by a Nexa switch.

What Im doing is to read in a Oregon wind sensor and add the value into Switchking as a datasource.
This works great.

Now starts the problem, Im trying to use eventghost together with the switchking plugin and make a macro that if the windspeed is over 4m/s send a On signal to the Nexa switch that then will activate the releay and prevent the Gardena system from watering. If the windspeed is below 4 m/s, I would like to have a Off signal sent to the Nexa switch allowing the Gardena system to do its jobb :-)

After some reading here I have come to the conclusion to create 2 macros in eventghost and under each macro put the windspeed event and then have a python script and a action to turn on (or off for the other macro) the Nexa switch.
My problem is that I cant get the python script right getting it to read the event and compare it to a value in the script that tells the macro to run or abort.

Anyone that are able to give some guidance here perhaps?

Regards
Anders

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Controlling a Nexa Switch based on windspeed

Post by krambriw » Thu Nov 19, 2015 5:01 am

It doesn't sound too complicated, so yes, we can help

You need to provide us with the following information:

In your next reply
- copy & paste your current python script as "code"
- copy & paste a screenshot of the wind data event (how it looks like)

anderspnilsson
Posts: 5
Joined: Wed Nov 18, 2015 9:45 pm

Re: Controlling a Nexa Switch based on windspeed

Post by anderspnilsson » Thu Nov 19, 2015 1:44 pm

Hi,

Thank you very much!

Here is the code Im trying to use, actually taken from one of your previus answers here on the forum and then slightly modified.
Since Im not familiar with coding at all (just have a lot of ideas that I want to realize) Im probably tottaly out of the blue with my modifications in your code.

Code: Select all

#Macro for Gardena vind on'

thePayload = eg.event.payload

if thePayload < 4:
    eg.StopMacro()

Code: Select all

#Macro for Gardena vind off'

thePayload = eg.event.payload

if thePayload > 4:
    eg.StopMacro()

Please find a picture attached of how it looks in EG.
The wind event is named: Switchking.DataSource.Vindhastighet.Barsebäck.(Genomsnitt)

Regards
Anders
Attachments
Event Ghost Gardena.jpg

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Controlling a Nexa Switch based on windspeed

Post by krambriw » Thu Nov 19, 2015 4:39 pm

Perfect,

Your scripts are very close to work :). Only a small modification is needed. The payload you receive in the event for the wind speed is a string. So we need to convert that into a float. Your scripts should look like this:

Code: Select all

#Macro for Gardena vind on'

thePayload = float(eg.event.payload)

if thePayload <= 4.0:
    eg.StopMacro()
    
    

#Macro for Gardena vind off'

thePayload = float(eg.event.payload)

if thePayload > 4.0:
    eg.StopMacro()

anderspnilsson
Posts: 5
Joined: Wed Nov 18, 2015 9:45 pm

Re: Controlling a Nexa Switch based on windspeed

Post by anderspnilsson » Thu Nov 19, 2015 6:35 pm

Thank you for the fast feedback.

Just tested it and unfortunately I get an error as can be seen in the attached picture.

Regards
Anders
Attachments
Skärmavbild 2015-11-19 kl. 19.34.15.png

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Controlling a Nexa Switch based on windspeed

Post by krambriw » Fri Nov 20, 2015 6:36 am

Oops,

I see now that the values typically are received as 9,6 (instead of 9.6 that is expected by python as a float...)

We can try to change the lines defining thePayload to this instead:

Code: Select all

thePayload = float(str(eg.event.payload).replace(',','.'))

anderspnilsson
Posts: 5
Joined: Wed Nov 18, 2015 9:45 pm

Re: Controlling a Nexa Switch based on windspeed

Post by anderspnilsson » Fri Nov 20, 2015 7:05 am

Thank you :-)

Just tried it but unfortunately there is till an error complaining about the value "invalid literal for float():None" as you can see in the attached picture.

Once again I really appreciate your support helping me with this :-)

Regards
Anders
Attachments
Skärmavbild 2015-11-20 kl. 08.01.50.png

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Controlling a Nexa Switch based on windspeed

Post by krambriw » Fri Nov 20, 2015 8:33 am

Alright,

Can we try the following, also add a print statement to the scripts so we can see how the payload actually look like

Code: Select all

print eg.event.payload
thePayload = float(eg.event.payload.replace(',','.'))

anderspnilsson
Posts: 5
Joined: Wed Nov 18, 2015 9:45 pm

Re: Controlling a Nexa Switch based on windspeed

Post by anderspnilsson » Fri Nov 20, 2015 11:31 am

Hi,

I think I know why I got the error now. Proabaly since I was to eager to try it out and pressed the play button "Execute Item",
and since there wasent any data collected at the time of me pressing the button I got the error.
If wating a while untill the event comes it actually works now.

As can be seen in the attached picture the macro triggers on the event and turns on the switch (I lowered the trigger value to 0.4 in the python script in order to test it)
It also prints the value nicely as can be seen in the EG log.

Thanks a lot for the great support!


Regards
Anders
Attachments
EG_1.jpg

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Controlling a Nexa Switch based on windspeed

Post by krambriw » Fri Nov 20, 2015 1:44 pm

Great,
nice idea for the application !

Best regards, Walter

Post Reply