Get status from LogoControl for Siemens Logo PLC

Post Reply
User avatar
DewGew
Posts: 65
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi
Domoticz version: V3.8102
Location: Sweden
Contact:

Get status from LogoControl for Siemens Logo PLC

Post by DewGew » Tuesday 05 September 2017 14:43

I have LogoControl installed in my RPI to control my siemens logo plc and now i want to get status from LogoControl to domoticz and use dzVents to control my plc.
I can check status with rest/json calls and looks like this example:

turn On = https://LogoControl:8088/rest/devices/1/methods/1
turn Off = https://LogoControl:8088/rest/devices/1/methods/2

check status = https://LogoControl:8088/rest/devices/1 ... es/1/value
(1=On 0 = Off)

any Ideas how to check status in dzVents?

// DewGew
Last edited by DewGew on Thursday 14 September 2017 8:20, edited 1 time in total.
Raspberry Pi 2B - domoticz - Aeon Labs Z-Stick GEN5 - RFlink gateway
NanoPi NEO-air - domoticz - REGO6XX interface

User avatar
DewGew
Posts: 65
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi
Domoticz version: V3.8102
Location: Sweden
Contact:

Re: Get status from LogoControl

Post by DewGew » Wednesday 06 September 2017 11:01

Maybe I can use this

Code: Select all

os.execute('curl -s "'..url..'" > /tmp/resultfile&')
How do I read the resultfile then?

//DewGew
Raspberry Pi 2B - domoticz - Aeon Labs Z-Stick GEN5 - RFlink gateway
NanoPi NEO-air - domoticz - REGO6XX interface

User avatar
BakSeeDaa
Posts: 414
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Get status from LogoControl

Post by BakSeeDaa » Thursday 07 September 2017 15:58

DewGew wrote:
Wednesday 06 September 2017 11:01
Maybe I can use this

Code: Select all

os.execute('curl -s "'..url..'" > /tmp/resultfile&')
How do I read the resultfile then?

//DewGew
It's not really specific for dzVents. It's more a Lua question.

Putting a command in the background to execute and get back later to check the results that has been stored in a file can be a good option if requesting an URL over the Internet. Doing it that way won't introduce delays in the Domoticz event queue in case the server takes time to respond. With that being said, if it's a local server in your LAN that's always available and answers fast you should read the result when doing the request. E.g. local result=assert(io.popen(url)). That method should be avoided though if going outside your LAN. There are several other scripts using this method that you can use as a starter. But again, it's not a specific dzVents question.

Cheers!
Best wishes

// บักสีดา

User avatar
DewGew
Posts: 65
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi
Domoticz version: V3.8102
Location: Sweden
Contact:

Re: Get status from LogoControl

Post by DewGew » Thursday 14 September 2017 8:19

Now I have LogoControl by http://www.frickelzeugs.de working with a dzVents script. I share it here if anyone is interested or maybe someone can build a python plugin.

LogoControl.lua

Code: Select all

--[[ 
	-- LogoControl script v1.0.0 --
	        by DewGew
	
	dzVents script to control and monitor Siemens Logo PLC 0Ba7 or OBa8 using 
	LogoControl by frickelzeugs as a bridge between domoticz and PLC.
	LogoControl download and manual: http://www.frickelzeugs.de/
	
	Control Domoticz devices thrue LogoControl I use shell script within LogoControl.
	./home/pi/LogoControl/Scripts/yourscriptfile.sh

	Switch Device 123 on or off:

	#!/bin/bash
	ip=127.0.0.1
	port=8080
	switchidx=123
	curl "http://$ip:$port/json.htm?type=command&param=switchlight&idx=$switchidx&switchcmd=On"
	or
	curl "http://$ip:$port/json.htm?type=command&param=switchlight&idx=$switchidx&switchcmd=Off"
	 
	then add 'trigger' in your LogoControl config file, example on PLC output Q1 (device 1 in LogoControl):
	
	<device id="1" name="Bedroom Light" type="light">
		<attribute id="1" name="Status" plc="myLogo" address="Q1" valueTextConverter="on_off" />
		<method id="1" name="on" plc="myLogo" address="150.0" script="Q1_on.sh" />
		<trigger plc="myLogo" address="150.0" datatype="bit">
        	<onValue value="1" method="1" />
   		</trigger>														  
		<method id="2" name="off" plc="myLogo" address="150.1" script="Q1_off.sh" />
		<trigger plc="myLogo" address="150.1" datatype="bit">
    		<onValue value="2" method="2" />
   		</trigger>	
	</device>
		
		
	Titel: logoControl.lua	
	Framework: dzVents 2.2.0
	Datum: 2017-09-14
]]
return {

	active = true,

	on = {
	    devices = {
	        'Q1',	-- Add domoticz devices that will trigger the script
	        'Q2',
		--	'Q3'	-- etc
	   }
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = "LogoControl script: " -- prefix added to every log message
	},

	execute = function(domoticz, device)
        
        local logoControlIP = "127.0.0.1"	-- LogoControl Ipadress
        local logoControlport = "8088"		-- LogoControl Port
        local logoControlDeviceNr = ""
        local logoControlDeviceAttrNr = ""
	 
	    if device.name == "Q1" then logoControlDeviceNr = 1 end		-- pair domoticz device with LogoControl device
	    if device.name == "Q1" then logoControlDeviceAttrNr = 1 end	-- pair domoticz device with LogoControl device Attribute eg. table at http://logocontrol:8088/rest/attributes (on/off status or value)
	    if device.name == "Q2" then logoControlDeviceNr = 5 end
	    if device.name == "Q2" then logoControlDeviceAttrNr = 6 end
		-- if device.name =="Q3" then logoControlDeviceNr = 3 end		-- etc.
	    -- if device.name =="Q3" then logoControlDeviceAttrNr = 3 end

	    json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
		local file=assert(io.popen('curl http://' .. logoControlIP ..':' .. logoControlport .. '/rest/attributes'))
		local raw = file:read('*all')
		file:close()   
        local logoControlAttributes = json:decode(raw)
		local logoOutputDevice = logoControlAttributes.attributeUpdates[logoControlDeviceAttrNr].D
		local logoOutput = logoControlAttributes.attributeUpdates[logoControlDeviceAttrNr].V
		local logoOutputText = logoControlAttributes.attributeUpdates[logoControlDeviceAttrNr].T
		
		domoticz.log('Checking status -- Device ' .. logoOutputDevice .. ' status  is ' .. logoOutput .. ' (' .. logoOutputText .. ')', domoticz.LOG_INFO)
        
        if device.state == 'On' and logoOutput == 0 then
            domoticz.openURL('http://' .. logoControlIP .. ':' .. logoControlport .. '/rest/devices/' .. logoControlDeviceNr .. '/methods/1')
		    domoticz.log('Switching on domoticz device ' .. device.name .. ' and LogoControl device ' .. logoControlDeviceNr,domoticz.LOG_INFO)
      
        elseif device.state == 'Off' and logoOutput == 1 then
            domoticz.openURL('http://' .. logoControlIP .. ':' .. logoControlport .. '/rest/devices/' .. logoControlDeviceNr .. '/methods/2')
		    domoticz.log('Switching off domoticz device ' .. device.name .. ' and LogoControl device ' .. logoControlDeviceNr,domoticz.LOG_INFO)
	    end
    end
Feel free to modify this code :)

//DewGew
Raspberry Pi 2B - domoticz - Aeon Labs Z-Stick GEN5 - RFlink gateway
NanoPi NEO-air - domoticz - REGO6XX interface

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest