Turning relay on automatically

5 years 10 months ago #2640 by s3lkies
Hello,

I have set up my ESP8266 with a relay attached to control some lights ,

Is there a way I can program them to come on at a certain time and turn off at a certain time?

Please Log in or Create an account to join the conversation.

5 years 10 months ago #2644 by NightOne
Hi there,

The easiest way is to create two automation programs that run on cron.... the you would simply use the driver helper to control the switch, this is assuming that you have set up the relay on the esp8266 to be controlled via EasyIOT

You would set the CRON part when you create the program... that means the time you want it to turn on.
(Please change the node address and the domain to match your setup)

public void Run()
{
DriverHelper.ProcessCommad(Domains.VIRTUAL, "N2S0", "ControlOn","");
}

The Second automation programn would be the time to turn off also set when you create the automation program
public void Run()
{
DriverHelper.ProcessCommad(Domains.VIRTUAL, "N2S0", "ControlOff","");

}

Please Log in or Create an account to join the conversation.

5 years 10 months ago #2653 by s3lkies
Thanks for that Nightone, however I'm having a problem getting that to work , can you please explain the code and I might be able to see where I'm going wrong here - also is this for Easyiot cloud? as I have mine set up on a server (raspberry pi )

Please Log in or Create an account to join the conversation.

5 years 10 months ago #2654 by NightOne
The code should work, the only reason that it should not work is the following:

When you created a new automation program it would have asked you for a name and a cron job, the format of the cron time is important, so here is a website that explains cron job format www.nncron.ru/help/EN/working/cron-format.htm or read EasyIOT automation documents here iot-playground.com/2-uncategorised/25-ea...er-automation-part-i

For testing I created a single (one) Automation program with the following cron job timing * * * * * this timing means that the cron job runs ever minute. I then have the following code in the program

public void Run()
{
DriverHelper.ProcessCommad(Domains.VIRTUAL, "N2S0", "ControlOn","");
}

You must change the following...... Look at the node name you want to change, meaning when you are on the EasyIOT website you should have a switch that when you toggle the switch the relay goes on or off..... Under the name of the switch is a node type and its name.

MySensors - Domains.MYSENSORS
RPiGPIO - Domains.RPIGPIO
Esp8266 - Domains.ESP8266
Virtual - Domains.VIRTUAL

Next it the node address in my example its N2S0... this must match your node name for your relay switch.

I then press update on the bottow right to "save" the automation script.... and then make sure that its enabled... when you click back once there is a slide switch to enable the program... then wait one minute and the relay should swtich "ON".

Then go back into the automation program that you made and change the following

"ControlOn" must become "ControlOff"... when press update again and wait another minute..... the relay should go off....

Now you know the program works... you need to create a second program with the correct cron timing

An example... the program that you have made can be called relay off..... change the cron timing from * * * * * to * 22 * * * this means it will turn off at 10pm each night.

the second program you make can be called relay on... change the timing for the cron to * 18 * * * this means it will turn on each day at 6pm.

I have found that creating NEW automation programs is better when you want to work with cron as sometimes I have found that just chaging exisiting programs didnt work for me, there is no reason why this should not run on RasPi

Hope this helps

Please Log in or Create an account to join the conversation.

Time to create page: 0.167 seconds

Forum latest

  • No posts to display.