AWST8802

Moderator: leecollings

Post Reply
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

AWST8802

Post by manjh »

I have an AWST8802 switch from KAKU. It is basically a double switch, with two up/down buttons.
I want to use this as a pulse for a LUA script, as a counter.
Problem when I define the switch as on/off is that the status of the switch stays "on".
How can I process a single pulse?
Hans
mrf68

Re: AWST8802

Post by mrf68 »

Why is "always on" a problem? Domoticz will notice that On is pressed even if the status is On. So in my opinion you can script it like "if On then value is value + 1".
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: AWST8802

Post by manjh »

Status stays "on". so the script will keep incrementing..
Hans
mrf68

Re: AWST8802

Post by mrf68 »

Take a look at this little video, I think it works.

http://weer.familie-frans.nl/domoticz/dc.mp4
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: AWST8802

Post by manjh »

I tried, but it fails.

Code:
counter = otherdevices_svalues('KeukenLevel')
counter = tonumber(counter)

commandArray = {}

if devicechanged['Keuken schakelaar links'] == 'on' then
print ('increment')
counter = counter + 1
commandArray['UpdateDevice'] = 2 .. '|0|' .. tostring{counter}
elseif devicechanged['Keuken schakelaar links'] == 'off' then
print ('decrement')
counter = counter - 1
commandArray['UpdateDevice'] = 2 .. '|0|' .. tostring{counter}
end

return commandArray

Log says:

Error: EventSystem: in Script_device_Schakelaar keuken links: [string "..."]:5: attempt to call global 'otherdevices_svalues' (a table value)

When I look at differences, the thing that jumps out is the definition of the counter. I tried creating a virtual device as counter, and it comes up in the utility tab as RFXMeter counter.

Can you give me the steps of how you created yours?
Hans
mrf68

Re: AWST8802

Post by mrf68 »

My 'Counter' is a virtual sensor, type Text. That is why I retrieve the info with otherdevices_svalues and convert it to a number so that I can calculate with it. When I read your 1st question, it wasn't clear to me what you wanted. Stating that an 'Always On' state is a problem, was something I doubted. I proved that it could work, with my video, I think.
Just typing over the code doesn't work. For instance, the '2' in 'commandArray['UpdateDevice'] = 2 .. '|0|' .. tostring(counter)' refers to the idx of my virtual Text sensor. The idx of your 'Keukenlevel' is probably not 2. And the '()' in 'counter = otherdevices_svalues('KeukenLevel')' needs to be '[]'.

What I did was:

create a switch, type Push On Button, name: PushOnButton
create a virtual sensor, type Text, name: Counter

Find the Idx for the virtual sensor (in Setup - Devices), in my case it is 2.

Then the script:

Code: Select all

counter = otherdevices_svalues['Counter']
counter = tonumber(counter)

commandArray = {}
if 
	devicechanged['PushOnButton'] == 'On'
then
	counter = counter + 1
	commandArray['UpdateDevice'] = 2 .. '|0|' .. tostring(counter)
end
return commandArray
This script won't work the first time, because the text sensor has no value. So you have to fill this text sensor with a numeric value. You can do that by replacing the first line with 'counter = 0'. Then revert the change.
After that, this script will read the value (as a string), then turns it into a number, and when the button is pressed, it will add 1 to the value and write is as a string in the text sensor.

Regards,
Martin
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest