Set Temperature using Lua

Moderator: leecollings

Post Reply
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Set Temperature using Lua

Post by thebeetleuk »

I want to set the temperature of a virtual device using something like...

commandArray['Temperature House'] = tostring(current)

.. which doesn't work. How can I do this without using the IDX?
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
User avatar
oeildefeu
Posts: 9
Joined: Saturday 28 December 2013 15:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Set Temperature using Lua

Post by oeildefeu »

why without IDX ?
Raspberry Pi 3 - Raspbian + Razberry (OpenZwave) + RFXtrx433
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Re: Set Temperature using Lua

Post by thebeetleuk »

Because I want to define the dummy temperature device by name (as a variable), and don't want to have to specify the IDX as well.
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Re: Set Temperature using Lua

Post by thebeetleuk »

anyone?
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
zofiel
Posts: 30
Joined: Sunday 19 July 2015 10:03
Target OS: -
Domoticz version:
Contact:

Re: Set Temperature using Lua

Post by zofiel »

Think that this option can't be enabled at the moment in lua.

you have to use the idx format
User avatar
jvdz
Posts: 2330
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Set Temperature using Lua

Post by jvdz »

This is an example of a script that can retrieve the IDX for a devicename which you then can use to set an device with its IDX:

Code: Select all

commandArray = {}

-- Load necessary Lua libraries
http = require "socket.http";
JSON = require "JSON";
server_url="http://192.168.0.xx:8080"

-- Function to retrieve the IDX for a DeviceName
function GetDeviceIDX(DeviceName)
	-- get device IDX from Domotics
	local DeviceIDX,result,record
	DeviceIDX = 99999
	DeviceURL="type=devices&order=name&used=true"
	t = server_url.."/json.htm?" .. DeviceURL
	jresponse, status = http.request(t)
	decoded_response = JSON:decode(jresponse)
	result = decoded_response['result']
	for i = 1, #result do
		record = result[i]
		if record['Name'] == DeviceName then
			DeviceIDX=record['idx']
			break
		end
	end
	return DeviceIDX
end

DeviceName="ThermostaatHK"
DeviceIDX = GetDeviceIDX(DeviceName)
if DeviceIDX == 99999 then
	print("  DeviceName "..DeviceName.." not found.")
else
	print("  DeviceName "..DeviceName.."  DeviceIDX="..DeviceIDX)
end

return commandArray
The required libraries and how to install can be found in the DTGBOT wiki.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Re: Set Temperature using Lua

Post by thebeetleuk »

thanks!!
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest