Welcome! Log In Create A New Profile

Advanced

automatic turning on and off of devices over a period of time

Posted by Willy 
automatic turning on and off of devices over a period of time
February 20, 2023 02:37PM
Hello,

A customer asks me to expand his cash register software.
He wants to be able to switch on certain devices, for example a lamp, for 30 minutes after the customer has paid for a service.

Perhaps this can only be done through intelligent sockets. They have an IP address and WiFi.

Maybe we can control this via commands from a WinDev program.
Does anyone know the best way to handle this.

Thank you in advance.
Willy Hermans.
Re: automatic turning on and off of devices over a period of time
February 20, 2023 03:17PM
Hi Willy,
buy some Tasmota relay.

[templates.blakadder.com]

Can be found on Aliexpress, company Athom is manufacturer
Link

Connect it to wifi and you can control this device with simple http request or via mqtt broker.
It can be programmed that your http request turn device on for 30 minutes.
There are versions with and without power meter so you can get power consuption for connected devices.

If you need some advanced scenarios for controling devices you can check Home Assistant [www.home-assistant.io]

BR,
Alen
Re: automatic turning on and off of devices over a period of time
February 21, 2023 10:42AM
I'll try this asap.

I think it works also fine with the latest sockets, lamps that we use with Google Assistant.

Thanks,

Willy Hermans.
Re: automatic turning on and off of devices over a period of time
February 28, 2023 02:21PM
Hello,

I've been searching for days but haven't found anything useful yet.

Is there no command that I send to the ip address of a lamp or socket that turns it on.

Can someone tell me in which direction I should start looking.

I have several lamps here that I can operate with the voice commands of google assistant. But that's not what I need.

A customer asks if I can connect devices to a cash register system via WiFi. The intention is that a customer who pays an hour in advance can use a device during that hour. (By supplying it with power) After that hour, the unit should be disconnected.

Should I search in the direction of sockets or should I use something like httprequest?

Does anyone have an idea.

Thank you in advance.

Willy Hermans.
Re: automatic turning on and off of devices over a period of time
March 03, 2023 01:20PM
Hi Willy,

I am using the Sonoff R3 inline unit. Works brilliantly using HTTP Requests. The unit costs about £10 UK.

We use them for several activities e.g. We use it for turning the electricity on /off for camping pitches. The person pays for so many days and at 11AM on the last day it turns it off.

All run on Android phone / webdev.
pao
Re: automatic turning on and off of devices over a period of time
March 03, 2023 04:10PM
We have used SONOFF MINIR4 to control the air conditioning devices, we turn them on 1/2 hour before the first employee of that room is scheduled to arrive and switch them off when the last employee leaves the room.

This is controlled by one service made with windev reading the T&A database and using the REST protocol (HTTP POST).

[sonoff.tech]

If it's only to control one lamp probably the SONOFF B02-BL/B05-BL can solve your problem.

[sonoff.tech]
[sonoff.tech]

Regards

Paulo Oliveira



Edited 2 time(s). Last edit at 03/03/2023 04:19PM by pao.
Re: automatic turning on and off of devices over a period of time
March 04, 2023 03:22PM
Hi Willy,
to simplify my previous post.

Device:
[www.athom.tech]
OR
[www.athom.tech]
OR
[www.athom.tech]

Connect device to wifi

Control via http request:
htt*://<ip>/cm?cmnd=Power%20TOGGLE
htt*://<ip>/cm?cmnd=Power%20On
htt*://<ip>/cm?cmnd=Power%20Off
htt*://<ip>/cm?user=admin&password=joker&cmnd=Power%20Toggle


To setup time ON for 1 hour you can use:
htt*://<ip>/cm?cmnd=PulseTime%203700


Documentation:
[tasmota.github.io]

Devices does not need internet to work.

Hope it helps

BR,
Alen



Edited 1 time(s). Last edit at 03/04/2023 03:25PM by slxslx.
Re: automatic turning on and off of devices over a period of time
March 04, 2023 03:48PM
This is the code to get the data from a sonoff r3 using WM . For Windev just use the URL

ws_info is ANSI string = [
{
"deviceid": "1000b8d2be",
"data": { }
}
]



i is int = 1
maReq is a httpRequest
myRep is a httpResponse
HttpVariant is a Variant


Edit_dets = ""


// WLanguage code used to call it by passing the parameter

maReq..URL = "[xxx.xxx.xxx.xxx];
maReq..ContentType = "application/json"
//maReq..ContentType=typeMimeJSON
maReq..Method = httpPost
maReq..Content = ws_info

myRep = RESTSend(maReq)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Edit_dets = myRep.Content
END

Hope this helps.

Mike
Re: automatic turning on and off of devices over a period of time
March 13, 2023 02:11PM
Thanks in advance.
This is already a long way for a beginner in home automation.

I think I should order such Sonoff to test.
Can the smart plug S26R2 be controlled in the same way?
Is the deviceID easy to find. Is this the MAC address ???

I have used following code in WinDev. If I understand correctly, this should also work in WinDev. I have used a socket from HEMA. (The Sonoff has yet to be delivered)

cWs_info is ANSI string = [
{
"deviceid":"10d561b3c1c8",
"data": { }
}
]



i is int = 1
maReq is a httpRequest
myRep is a httpResponse
vHttpVariant is a Variant


EDT_Dets = ""


// WLanguage code used to call it by passing the parameter

maReq..URL = "[192.168.0.4]"
maReq..ContentType = "application/json"
//maReq..ContentType=typeMimeJSON
maReq..Method = httpPost
maReq..Content = cWs_info

Trace(maReq..Content)
Trace(maReq..ContentType)

myRep = RESTSend(maReq)


IF ErrorOccurred THEN
	Error(ErrorInfo(errFullDetails))
ELSE
	EDT_Dets = myRep.Content
END


So I don't expect this to work well yet, but I do expect an answer to come.
However, I get the following error message.

WL call:
Process of 'Click BTN_NoName1' (WIN_Main.BTN_NoName1), line 31
'RESTSend' function, syntax 0

What happened?
System error sending HTTP request.

Error code: 100138
Level: non-fatal error

Dump of the error of 'wd240com64.dll' module (24.0.56.1).
Debugging information:
Fonction (10,424)
Additional Information:
EIT_PILEWL :
Click BTN_NoName1 (WIN_Main.BTN_NoName1), line 31
EIT_DATEHEURE : 13/03/2023 14:09:46
EIT_TYPE_WDFILE : <2>
EIT_IDCODE : <18>

Thanks,
Willy Hermans
Re: automatic turning on and off of devices over a period of time
March 14, 2023 02:09PM
Hi Willy,

I have just tested the below code using WM24 Express and it works talking to a Sonoff R3. I made a button called "CMD_INFO"

ws_info is ANSI string = [
{
"deviceid": "1000b8d2be",
"data": { }
}
]



i is int = 1
maReq is a httpRequest
myRep is a httpResponse
HttpVariant is a Variant


Edit_dets = ""


// WLanguage code used to call it by passing the parameter

maReq..URL = "[192.168.51.56];
maReq..ContentType = "application/json"
maReq..Method = httpPost
maReq..Content = ws_info

myRep = RESTSend(maReq)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Edit_dets = myRep.Content
END

edit_dets= {"seq":8,"error":0,"data":{"switch":"off","startup":"off","pulse":"off","pulseWidth":500,"ssid":"FBS-LTD","otaUnlock":false,"fwVersion":"3.6.0","deviceid":"1000b8d2be","bssid":"5c:b1:3e:3f:d3:44","signalStrength":-53}}


Hope this helps,

Mike
Re: automatic turning on and off of devices over a period of time
April 03, 2023 05:09PM
The Sonoff Dual R3 Wi-FI Smart Switch is delivered.

I've used this code

ws_info is ANSI string = [
{
"deviceid":"4022D8FEB724",
"data":{}
}
]



i is int = 1
maReq is a httpRequest
myRep is a httpResponse
HttpVariant is a Variant


EDIT_Dets = ""


// WLanguage code used to call it by passing the parameter

maReq..URL = "192.168.1.102"
maReq..ContentType = "application/json"
maReq..Method = httpPost
maReq..Content = ws_info

myRep = RESTSend(maReq)
IF ErrorOccurred THEN
	Error(ErrorInfo(errFullDetails))
ELSE
	EDIT_Dets = myRep.Content
END

I've still an error on the line
myRep = RESTSend(maReq)

It is a Syntax 0
error code 100138
Level non fatal error.

I've tried it with different small editions.
Brackets in Mac adress and so on.

Has anyone an idea.

Thanks
Willy Hermans.
Re: automatic turning on and off of devices over a period of time
April 03, 2023 05:57PM
Willy,

Are you using it straight out of the box?

If you are, you have to flash it to be into DIY mode as opposed to general use.

[sonoff.tech] will give you everything that you need. I work in DIY mode.

Kindest regards,

Mike
pao
Re: automatic turning on and off of devices over a period of time
April 03, 2023 06:21PM
did you try with http:// at the the beginnig of the URL and using port 8081?

Regards

Paulo Oliveira



Edited 1 time(s). Last edit at 04/03/2023 06:24PM by pao.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: