Lua Sample Script for Temperature Sensor

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
nettworker
Posts: 14
Joined: Thursday 16 February 2017 6:18
Target OS: -
Domoticz version:
Contact:

Lua Sample Script for Temperature Sensor

Post by nettworker »

Is there a sample Lua Script where i can see how to react on a temperature sensor and switch another device on?

Thx
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Lua Sample Script for Temperature Sensor

Post by Siewert308SW »

Something like this...
Beware, it's a personal script and not usable as you maybe don't have a UPS (Pico Power) or some functions.

Code: Select all

--[[
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

	@ activity_heating.lua
	@ author	: Siewert Lameijer
	@ since		: 1-1-2015
	@ updated	: 13-3-2017
	@ Script to switch ON/OFF heating when someone @ home or not
	
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
--]]

-- Someonehome Switch
	local someonehome					= 'Iemand Thuis'
	local nobody_home					= 'Niemand Thuis'
	
-- Nest Various
	local nest_setpoint					= 'Nest - Setpoint'
	local nest_setpoint_idx				= 77
	local setpoint_low					= 17
	local setpoint_high					= 21
	
-- Various Switches
	local pico_power					= 'PIco RPi Powered'
	
--
-- **********************************************************
-- Heating On when someone @ home
-- **********************************************************
--
	setpoint_current_temp	= tonumber(otherdevices_svalues[nest_setpoint])
	
	if otherdevices[someonehome] == 'On' 
	and otherdevices[pico_power] == 'On' 
	and setpoint_current_temp == setpoint_low	
    and timebetween("08:30:00","22:00:00")	
	then
		timer_body = 'Someone at home, turning ON heating'	
		timer_body0 = 'Current Setpoint: '..setpoint_current_temp..''
		timer_body1 = 'New Setpoint: '..setpoint_high..''
		commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_high..""		
	end
	
	if otherdevices[nobody_home] == 'On' and otherdevices[pico_power] == 'On' and setpoint_current_temp ~= setpoint_low then
		timer_body = 'Nobody at home, turning OFF heating'	
		timer_body0 = 'Current Setpoint: '..setpoint_current_temp..''
		timer_body1 = 'New Setpoint: '..setpoint_low..''
		commandArray["OpenURL"]="http://"..domoticz.ip..":"..domoticz.port.."/json.htm?type=command&param=udevice&idx="..nest_setpoint_idx.."&nvalue=0&svalue="..setpoint_low..""		
	end
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
Post Reply

Who is online

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