uniPi I/O hardware script for LUA

Moderator: leecollings

Post Reply
spudgunman
Posts: 32
Joined: Tuesday 26 May 2015 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Seattle WA, USA
Contact:

uniPi I/O hardware script for LUA

Post by spudgunman »

so I am not a good enough coder to make a change to the domoticz source for a new hardware type (I couldnt figure out where to start really) so I just hacked up a huge LUA script that makes the uniPi hardware work.. this script is in beta still but most all functions work minus the one wire (I just use OWFS so havent gone to the trouble yet in this script) and the Analog output isnt 100% awesome functionality.. I will update post when there is worthy updates..

I would love some feedback and testing if you have the hardware - its good hardware to make your home security system with.

I also hope the code paste works [Expand the spoiler below to see code, did this to keep thread looking neat]
Spoiler: show

Code: Select all

--uniPi Domoticz LUA Script b0.98
------------------------------------------------------------------------------------
-- Setup Instructions
--
-- Required that to use this script you have Domoticz fully working on a raspberryPi
-- Additionally you will need the uniPi hardware module installed and the evok uniPI API working
-- you can use the installer or my manual tutorial here http://unipi.technology/forum/viewtopic.php?f=6&t=95
-- it is mandatory that evok API/website is working correctly before this script will function!
--
-- This script also requires json for lua http://regex.info/blog/lua/json
--  rough install guide create the required directory 'sudo mkdir /usr/local/share/lua/5.2/'
--  put the json script in the directory 'sudo cp json.lua /usr/local/share/lua/5.2/'
--
-- In Domoticz you will need to create virtual hardware device and name it something like uniPi
-- In the Domoticz hardware tab click setup for uniPi and add 8 virtual 'switch' devices for the relays
-- name the switch devices whatever you want this script assumes the name "uniPi Relay1","uniPi Relay2" etc
-- Go to the device tab in Domoticz and make note of the idX number (the far left column near the icons)
-- Now update the user settings below for virtual device names and IDx values to match your config in domoticz
--
-- Do the same for the remaining devices (for analog input use voltage devices, for digital inputs use switches
-- for analog output use a slider/dimmer switch
--
-- beta not working for one wire therm via this script yet either in beta yet
--
--
--

-------------------------------------
-- Evok API hostname and port      --
-- normally just need port changed --
-------------------------------------

evokurl = "localhost:8181"

-------------------------------------
-- Domoticz JSON hostname:port	   --
-------------------------------------

domoticzjson = "localhost:8080"

----------------------------------------------------------------
-- User Settings Below for Virtual Device Names and IDx values--
----------------------------------------------------------------

--the following is the IDx for the relay switches with uniPi there are 8 relays create as normal switches
idxr1 = 40
relay1name = "uniPi Relay1"
idxr2 = 41
relay2name = "uniPi Relay2"
idxr3 = 42
relay3name = "uniPi Relay3"
idxr4 = 43
relay4name = "uniPi Relay4"
idxr5 = 44
relay5name = "uniPi Relay5"
idxr6 = 45
relay6name = "uniPi Relay6"
idxr7 = 46
relay7name = "uniPi Relay7"
idxr8 = 47
relay8name = "uniPi Relay8"

--the following is the IDx for the analog inputs with uniPi there are 2 inputs you should create them as virtual voltage meters
--to use these you also need to create a user variable as a floating variable and name it 'ai1_value' assign a default level of zero
--and respectivly 'ai2_value' for the 2nd sensor also floating and also starting with zero

idxai1 = 48
ai1name = "uniPi AnalogIn1"
idxai2 = 49
ai2name = "uniPi AnalogIn2"

--the following is the IDx for the analog outputs with uniPi there is 1 output create as a normal switch

idxao1 = 52
ao1name = "uniPi AnalogOut1"

--the following is the IDx for the digital inputs with uniPi there are 12 inputs create as normal switches

idxdi1 = 51
di1name = "uniPi Digital Input1"
idxdi2 = 65
di2name = "uniPi Digital Input2"
idxdi3 = 66
di3name = "uniPi Digital Input3"
idxdi4 = 67
di4name = "uniPi Digital Input4"
idxdi5 = 68
di5name = "uniPi Digital Input5"
idxdi6 = 69
di6name = "uniPi Digital Input6"
idxdi7 = 70
di7name = "uniPi Digital Input7"
idxdi8 = 71
di8name = "uniPi Digital Input8"
idxdi9 = 72
di9name = "uniPi Digital Input9"
idxdi10 = 601
di10name = "uniPi Digital Input10"
idxdi11 = 611
di11name = "uniPi Digital Input11"
idxdi12 = 621
di12name = "uniPi Digital Input12"

------------------------------------------------------------------------------
--the following is the one wire tempature sensors, required that you update 
--with your SN unique to your one wire device, this can be obtained by issuing
--the following to the uniPI API http://your.system.ip:PORT/rest/all
--then figure out which devices in the dev.temp you want to monitor.
--there is no limit to the devices here
------------------------------------------------------------------------------

OWSN1 = "2814228A060000F1"
OWSN2 = "updateMe"
OWSN3 = "updateMe"
OWSN4 = "updateMe"

------------------------------------------------------------------------------------------
-- uniPi Domoticz Lua Script
------------------------------------------------------------------------------------------
local n=0
json = require("json")

--reads all the data from the uniPi API System for parsing (this could be moved to a time script)
local unipi_json_data = io.popen("wget -qO- 'http://".. evokurl .. "/rest/all'")
raw_unipi_data = unipi_json_data:read("*a")
unipiRead = json:decode(raw_unipi_data)
unipi_json_data:close()

for key,value in pairs(unipiRead) do
n=n+1

-----------input device types----------------------
if unipiRead[n].dev == "input" then

if unipiRead[n].circuit == "1" then
digital1 =unipiRead[n].value
end

if unipiRead[n].circuit == "2" then
digital2 =unipiRead[n].value
end

if unipiRead[n].circuit == "3" then
digital3 =unipiRead[n].value
end

if unipiRead[n].circuit == "4" then
digital4 =unipiRead[n].value
end

if unipiRead[n].circuit == "5" then
digital5 =unipiRead[n].value
end

if unipiRead[n].circuit == "6" then
digital6 =unipiRead[n].value
end

if unipiRead[n].circuit == "7" then
digital7 =unipiRead[n].value
end

if unipiRead[n].circuit == "8" then
digital8 =unipiRead[n].value
end

if unipiRead[n].circuit == "9" then
digital9 =unipiRead[n].value
end

if unipiRead[n].circuit == "10" then
digital10 =unipiRead[n].value
end

if unipiRead[n].circuit == "11" then
digital11 =unipiRead[n].value
end

if unipiRead[n].circuit == "12" then
digital12 =unipiRead[n].value
end

end

-----------temp device types-----------------------
if unipiRead[n].dev == "temp" then

if unipiRead[n].circuit == OWSN1 then
temp1 = unipiRead[n].value
end

if unipiRead[n].circuit == OWSN2 then
temp2 = unipiRead[n].value
end

if unipiRead[n].circuit == OWSN3 then
temp3 = unipiRead[n].value
end

if unipiRead[n].circuit == OWSN4 then
temp4 = unipiRead[n].value
end

end

-----------analog output device types---------------
if unipiRead[n].dev == "ao" then

if unipiRead[n].circuit == "1" then
ao1 = unipiRead[n].value
end

end

-----------analog input device types---------------
if unipiRead[n].dev == "ai" then

if unipiRead[n].circuit == "1" then
ai1 = unipiRead[n].value
end

if unipiRead[n].circuit == "2" then
ai2 = unipiRead[n].value
end

end

-----------relay device types-----------------------
if unipiRead[n].dev == "relay" then

if unipiRead[n].circuit == "1" then
relay1 = unipiRead[n].value
end

if unipiRead[n].circuit == "2" then
relay2 = unipiRead[n].value
end

if unipiRead[n].circuit == "3" then
relay3 = unipiRead[n].value
end

if unipiRead[n].circuit == "4" then
relay4 = unipiRead[n].value
end

if unipiRead[n].circuit == "5" then
relay5 = unipiRead[n].value
end

if unipiRead[n].circuit == "6" then
relay6 = unipiRead[n].value
end

if unipiRead[n].circuit == "7" then
relay7 = unipiRead[n].value
end

if unipiRead[n].circuit == "8" then
relay8 = unipiRead[n].value
end

end
-----------------------------
end --ends the read main loop

-----------------------------
commandArray = {}
-----------------------Relay One----------------------------
if devicechanged[relay1name] then

if ((otherdevices[relay1name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay one")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/1 --post-data='value=0'") 
end

if ((otherdevices[relay1name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/1 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay one") 
end

else

if relay1 == 1 then
if ((otherdevices[relay1name] == 'Off') ) then commandArray[1] = {['UpdateDevice'] = idxr1 .. '|1|On'} end
elseif relay1 == 0 then
if ((otherdevices[relay1name] == 'On') ) then commandArray[1] = {['UpdateDevice'] = idxr1 .. '|0|Off'} end
else
print("uniPi relay one error") 
end

end
-----------------------Relay Two----------------------------
if devicechanged[relay2name] then

if ((otherdevices[relay2name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay two")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/2 --post-data='value=0'") 
end

if ((otherdevices[relay2name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/2 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay two") 
end

else

if relay2 == 1 then
if ((otherdevices[relay2name] == 'Off') ) then commandArray[2] = {['UpdateDevice'] = idxr2 .. '|1|On'} end
elseif relay2 == 0 then
if ((otherdevices[relay2name] == 'On') ) then commandArray[2] = {['UpdateDevice'] = idxr2 .. '|0|Off'} end
else
print("uniPi relay two error") 
end

end
-----------------------Relay Three----------------------------
if devicechanged[relay3name] then

if ((otherdevices[relay3name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay three")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/3 --post-data='value=0'") 
end

if ((otherdevices[relay3name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/3 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay three") 
end

else

if relay3 == 1 then
if ((otherdevices[relay3name] == 'Off') ) then commandArray[3] = {['UpdateDevice'] = idxr3 .. '|1|On'} end
elseif relay3 == 0 then
if ((otherdevices[relay3name] == 'On') ) then commandArray[3] = {['UpdateDevice'] = idxr3 .. '|0|Off'} end
else
print("uniPi relay three error") 
end

end
-----------------------Relay Four----------------------------
if devicechanged[relay4name] then

if ((otherdevices[relay4name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay four")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/4 --post-data='value=0'") 
end

if ((otherdevices[relay4name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/4 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay four") 
end

else

if relay4 == 1 then
if ((otherdevices[relay4name] == 'Off') ) then commandArray[4] = {['UpdateDevice'] = idxr4 .. '|1|On'} end
elseif relay4 == 0 then
if ((otherdevices[relay4name] == 'On') ) then commandArray[4] = {['UpdateDevice'] = idxr4 .. '|0|Off'} end
else
print("uniPi relay four error") 
end

end
-----------------------Relay Five----------------------------
if devicechanged[relay5name] then

if ((otherdevices[relay5name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay five")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/5 --post-data='value=0'") 
end

if ((otherdevices[relay5name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/5 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay five") 
end

else

if relay5 == 1 then
if ((otherdevices[relay5name] == 'Off') ) then commandArray[5] = {['UpdateDevice'] = idxr5 .. '|1|On'} end
elseif relay5 == 0 then
if ((otherdevices[relay5name] == 'On') ) then commandArray[5] = {['UpdateDevice'] = idxr5 .. '|0|Off'} end
else
print("uniPi relay five error") 
end

end
-----------------------Relay Six----------------------------
if devicechanged[relay6name] then

if ((otherdevices[relay6name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay six")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/6 --post-data='value=0'") 
end

if ((otherdevices[relay6name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/6 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay six") 
end

else

if relay6 == 1 then
if ((otherdevices[relay6name] == 'Off') ) then commandArray[6] = {['UpdateDevice'] = idxr6 .. '|1|On'} end
elseif relay6 == 0 then
if ((otherdevices[relay6name] == 'On') ) then commandArray[6] = {['UpdateDevice'] = idxr6 .. '|0|Off'} end
else
print("uniPi relay six error") 
end

end
-----------------------Relay Seven----------------------------
if devicechanged[relay7name] then

if ((otherdevices[relay7name] == 'Off') ) then 
print("Sending Power OFF to uniPi relay seven")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/7 --post-data='value=0'") 
end

if ((otherdevices[relay7name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/7 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay seven") 
end

else

if relay7 == 1 then
if ((otherdevices[relay7name] == 'Off') ) then commandArray[7] = {['UpdateDevice'] = idxr7 .. '|1|On'} end
elseif relay7 == 0 then
if ((otherdevices[relay7name] == 'On') ) then commandArray[7] = {['UpdateDevice'] = idxr7 .. '|0|Off'} end
else
print("uniPi relay seven error") 
end

end
-----------------------Relay Eight----------------------------
if devicechanged[relay8name] then

if ((otherdevices[relay8name] == 'Off') ) then 
print("uniPi: Sending Power OFF to uniPi relay eight")
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/8 --post-data='value=0'") 
end

if ((otherdevices[relay8name] == 'On') ) then 
io.popen("wget -qO- http://".. evokurl .. "/rest/relay/8 --post-data='value=1'")
print("uniPi: Sending Power ON to uniPi relay eight") 
end

else

if relay8 == 1 then
if ((otherdevices[relay8name] == 'Off') ) then commandArray[8] = {['UpdateDevice'] = idxr8 .. '|1|On'} end
elseif relay8 == 0 then
if ((otherdevices[relay8name] == 'On') ) then commandArray[8] = {['UpdateDevice'] = idxr8 .. '|0|Off'} end
else
print("uniPi relay eight error") 
end

end

-----------------------Analog Output One----------------------------
--this is currently only one way value settings, also no adjustment for the 11-15 range on the domoticz slider its all considered 100%

if devicechanged[ao1name] then
ao1_current_slider = tonumber(otherdevices_svalues[ao1name])
print("uniPi: Sending value " .. ao1_current_slider .. " to Analog Out")
io.popen("wget -qO- http://".. evokurl .. "/rest/ao/1 --post-data='value=" .. ao1_current_slider .. "'") 
end

-----------------------Analog Input One-----------------------------
ai1data = "http://" .. domoticzjson .. "/json.htm?type=command&param=udevice&idx=" .. idxai1 .. "&nvalue=0&svalue=" .. string.format("%.3f", ai1)
ai1_last_value = uservariables["ai1_value"]
ai1_current_value = string.format("%.1f", ai1)
if ai1_current_value == "0.0" then ai1_current_value = tonumber(ai1_current_value) end

if ai1_last_value == nil then
         print("uniPi Error: User variable not set for : Analog Input One 'ai1_value'")
end

if tostring(ai1_current_value) == tostring(ai1_last_value) then
--nothing changed
else
commandArray['OpenURL'] = ai1data
commandArray['Variable:ai1_value'] = ai1_current_value
end

-----------------------Analog Input Two----------------------------
local ai2data = "http://" .. domoticzjson .. "/json.htm?type=command&ampparam=udevice&idx=" .. idxai2 .. "&nvalue=0&svalue=" .. string.format("%.3f", ai2)
ai2_last_value = uservariables["ai2_value"]
ai2_current_value = string.format("%.1f", ai2)
if ai2_current_value == "0.0" then ai2_current_value = tonumber(ai2_current_value) end

if ai2_last_value == nil then
         print("uniPi Error: User variable not set for : Analog Input Two 'ai2_value'")
end

if tostring(ai2_current_value) == tostring(ai2_last_value) then
--nothing changed
else
commandArray['OpenURL'] = ai2data
commandArray['Variable:ai2_value'] = ai2_current_value
end

-----------------------Digital Input One----------------------------
if digital1 == 1 then
if ((otherdevices[di1name] == 'Off') ) then commandArray[21] = {['UpdateDevice'] = idxdi1 .. '|1|On'} end
elseif digital1 == 0 then
if ((otherdevices[di1name] == 'On') ) then commandArray[21] = {['UpdateDevice'] = idxdi1 .. '|0|Off'} end
else
print("uniPi digital input one error") 
end

-----------------------Digital Input Two----------------------------
if digital2 == 1 then
if ((otherdevices[di2name] == 'Off') ) then commandArray[22] = {['UpdateDevice'] = idxdi2 .. '|1|On'} end
elseif digital2 == 0 then
if ((otherdevices[di2name] == 'On') ) then commandArray[22] = {['UpdateDevice'] = idxdi2 .. '|0|Off'} end
else
print("uniPi digital input two error") 
end

-----------------------Digital Input Three----------------------------
if digital3 == 1 then
if ((otherdevices[di3name] == 'Off') ) then commandArray[23] = {['UpdateDevice'] = idxdi3 .. '|1|On'} end
elseif digital3 == 0 then
if ((otherdevices[di3name] == 'On') ) then commandArray[23] = {['UpdateDevice'] = idxdi3 .. '|0|Off'} end
else
print("uniPi digital input three error") 
end

-----------------------Digital Input Four----------------------------
if digital4 == 1 then
if ((otherdevices[di4name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi4 .. '|1|On'} end
elseif digital4 == 0 then
if ((otherdevices[di4name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi4 .. '|0|Off'} end
else
print("uniPi digital input four error") 
end

-----------------------Digital Input Five----------------------------
if digital5 == 1 then
if ((otherdevices[di5name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi5 .. '|1|On'} end
elseif digital5 == 0 then
if ((otherdevices[di5name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi5 .. '|0|Off'} end
else
print("uniPi digital input Five error") 
end

-----------------------Digital Input Six----------------------------
if digital6 == 1 then
if ((otherdevices[di6name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi6 .. '|1|On'} end
elseif digital6 == 0 then
if ((otherdevices[di6name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi6 .. '|0|Off'} end
else
print("uniPi digital input Six error") 
end

-----------------------Digital Input Seven----------------------------
if digital7 == 1 then
if ((otherdevices[di7name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi7 .. '|1|On'} end
elseif digital7 == 0 then
if ((otherdevices[di7name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi7 .. '|0|Off'} end
else
print("uniPi digital input Seven error") 
end

-----------------------Digital Input Eight----------------------------
if digital8 == 1 then
if ((otherdevices[di8name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi8 .. '|1|On'} end
elseif digital8 == 0 then
if ((otherdevices[di8name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi8 .. '|0|Off'} end
else
print("uniPi digital input Eight error") 
end

-----------------------Digital Input Nine----------------------------
if digital9 == 1 then
if ((otherdevices[di9name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi9 .. '|1|On'} end
elseif digital9 == 0 then
if ((otherdevices[di9name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi9 .. '|0|Off'} end
else
print("uniPi digital input Nine error") 
end

-----------------------Digital Input Ten----------------------------
if digital10 == 1 then
if ((otherdevices[di10name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi10 .. '|1|On'} end
elseif digital10 == 0 then
if ((otherdevices[di10name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi10 .. '|0|Off'} end
else
print("uniPi digital input Ten error") 
end

-----------------------Digital Input Eleven----------------------------
if digital11 == 1 then
if ((otherdevices[di11name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi11 .. '|1|On'} end
elseif digital11 == 0 then
if ((otherdevices[di11name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi11 .. '|0|Off'} end
else
print("uniPi digital input Eleven error") 
end

-----------------------Digital Input Twelve----------------------------
if digital12 == 1 then
if ((otherdevices[di12name] == 'Off') ) then commandArray[24] = {['UpdateDevice'] = idxdi12 .. '|1|On'} end
elseif digital12 == 0 then
if ((otherdevices[di12name] == 'On') ) then commandArray[24] = {['UpdateDevice'] = idxdi12 .. '|0|Off'} end
else
print("uniPi digital input Twelve error") 
end

return commandArray
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

Hi spudgunman,

Your post is a few months old and I was wondering if you maybe have an update? I successfully installed Domoticz and the UniPi
UniPi.PNG
UniPi.PNG (16.84 KiB) Viewed 6025 times
Do you know what the next step would be to let Domoticz understand his expansion board?

Any help would be appreciated. For example a step-by-step instruction how to install the script.

Thank you in advance
atagesson
Posts: 7
Joined: Wednesday 20 January 2016 15:41
Target OS: -
Domoticz version:
Contact:

Re: uniPi I/O hardware script for LUA

Post by atagesson »

Works great, thanks
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

atagesson wrote:Works great, thanks
Do you have some advice for me how to install the script?
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by proohu01 »

It would be great if the UniPi worked with MQTT and Node-RED (both are included in the Raspberry Pi Domoticz image)
http://unipi.technology/wiki/Controllin ... BM_Bluemix

I am still looking to replace my PiFace. The UniPi is a bit more expensive but seems to be able to do a lot more.
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
Poelie
Posts: 1
Joined: Monday 15 February 2016 22:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: uniPi I/O hardware script for LUA

Post by Poelie »

It's working great only my inputs are not refreshed in domoticz when I press a pushbutton. Only when i do an action in the domoticz webintarface ( activation of the lua script(~/domoticz/scripts/lua/script_device_UNIPI.lua)) i will change.

So when i push the button i want to see it on my domoticz without doing a action in the domoticz webinterface. => script_device_UNIPI.lua must run every second instead of waiting on a action from domotiz.

Does anyone know a solution?
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

The good news:
- Domoticz is running fine! More hardware is on my wish list...
- ImperiHome is running
- UniPi installed and controllable via webinterface
Screenshots.PNG
Screenshots.PNG (140.28 KiB) Viewed 5798 times
UniPi.JPG
UniPi.JPG (79.58 KiB) Viewed 5798 times
The challenge however: how can Domoticz and UniPi work together!? I created all the virtual sensors and switches in Domoticz. I installed Node-RED and can switch the relais by clicking on the nodes in the flow.
192.168.0.176-1880 and 8080.PNG
192.168.0.176-1880 and 8080.PNG (76.54 KiB) Viewed 5798 times
In the script folder

Code: Select all

pi@raspberrypi ~/domoticz/scripts/lua $ ls
5.2       script_UniPi_domoticz.lua  script_time_demo.lua
JSON.lua  script_device_demo.lua
pi@raspberrypi ~/domoticz/scripts/lua $
JSON and the above UniPi script are placed. The latter has been edited by the virtual switches (idxr numbers).
What step am I missing!? Do I have to run the scripts or does this automatically start on reboot? Domoticz cannot control the relays nor recognises the sensors.
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

For those looking for the solution: see the UniPi forum http://unipi.technology/forum/viewtopic.php?f=13&t=125
filipvdv
Posts: 3
Joined: Thursday 04 August 2016 0:03
Target OS: -
Domoticz version:
Contact:

Re: uniPi I/O hardware script for LUA

Post by filipvdv »

Hello

I got the Unipi working with Domoticz. Relays are working perfect via lua scripting or the Unipi control page.

I cannot get the digital inputs working. DOmoticz doesn't seem to register the switch update.

I can see the value going from 0 to 1 when i perform a "wget -qO ..." on the raspberry. The Unipi Control page also indicates its "On".

Unfortunalely Domoticz doesn't see the update.

The device naming and idx assignment is correct. I tripple checked it.
I also tried debugging the lua script from the Domoticz interface, where to some point the "1" value can be read and printed in the logs. It doesn't get to the eg. "uniPi Digital Input1" switch.

Any help very welcome
filipvdv
Posts: 3
Joined: Thursday 04 August 2016 0:03
Target OS: -
Domoticz version:
Contact:

Re: uniPi I/O hardware script for LUA

Post by filipvdv »

It seems when I apply 24v to the digital input 1 this does not trigger the device script. Thats why its not registered in domoticz.

When for example I apply 24v to input 1 and I trigger a relay this does activate the device script. Then the input is set to on in domoticz.

Now I need to figure out why the digital input does not trigger the device script. Or a workaround.

Any ideas?
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

I also have some difficulties with the digital input. I have some el cheapo sensors https://www.hobbyelectronica.nl/product ... ensor-ldr/ in an effort to read my analogue power meter. They run on 5V. The blinking of the LED triggers the sensor (after changing the sensitivity right). The sensor triggers the UniPi because I see the LED on the UniPi board blinking at the same time. However Domoticz doesn't see the utility device nor the pulses. Did you make some progress?

The log file is nagging many times a minute:

Code: Select all

 2016-09-02 19:57:06.310 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:11.473 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:26.891 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:26.966 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:37.755 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:38.735 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:42.472 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:43.275 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:57.093 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2016-09-02 19:57:57.163 Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_UniPi.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'} 
Has it something to do with the user variables?
User variables.PNG
User variables.PNG (23.24 KiB) Viewed 5061 times
ESFnl
Posts: 41
Joined: Saturday 26 December 2015 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: The Netherlands
Contact:

Re: uniPi I/O hardware script for LUA

Post by ESFnl »

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests