mtx-evohome.lua /size: 3651 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
mtx-evohome
'
]
=
{
2
version
=
1
.
002
,
3
comment
=
"
script to fetch data from a evohome device
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
evohome
=
require
(
"
util-evo
"
)
10 11
local
formatters
=
string
.
formatters
12 13
-- the script
14 15
local
helpinfo
=
[[
16<?xml version="1.0"?> 17<application> 18 <metadata> 19 <entry name="name">mtx-evohome</entry> 20 <entry name="detail">Evohome Fetcher</entry> 21 <entry name="version">1.00</entry> 22 </metadata> 23 <flags> 24 <category name="basic"> 25 <subcategory> 26 <flag name="collect"><short>collect data from device</short></flag> 27 <flag name="update"><short>update data from device</short></flag> 28 <flag name="presets"><short>file with authenciation data</short></flag> 29 <flag name="auto"><short>fetch temperature data every hour</short></flag> 30 <flag name="port"><short>server port when running the service, default: 8068</short></flag> 31 <flag name="host"><short>server host when running the service, default: localhost</short></flag> 32 </subcategory> 33 </category> 34 </flags> 35 <examples> 36 <category> 37 <title>Example</title> 38 <subcategory> 39 <example><command>mtxrun --script evohome --collect --presets=c:/data/develop/domotica/code/evohome-presets.lua</command></example> 40 <example><command>mtxrun --script evohome --server --presets=c:/data/develop/domotica/code/evohome-presets.lua</command></example> 41 </subcategory> 42 </category> 43 </examples> 44</application> 45
]]
46 47
local
application
=
logs
.
application
{
48
name
=
"
mtx-evohome
"
,
49
banner
=
"
Evohome Fetcher 1.00
"
,
50
helpinfo
=
helpinfo
,
51
}
52 53
local
report
=
application
.
report
54 55
scripts
=
scripts
or
{
}
56
scripts
.
evohome
=
scripts
.
evohome
or
{
}
57 58
local
arguments
=
environment
.
arguments
59
local
files
=
environment
.
files
60 61
function
scripts
.
evohome
.
collect
(
)
62
local
presets
=
arguments
.
presets
63
local
delay
=
tonumber
(
arguments
.
delay
)
or
15
*
60
*
60
64
if
presets
then
65
presets
=
evohome
.
helpers
.
loadpresets
(
presets
)
66
end
67
if
presets
then
68
local
function
fetch
(
)
69
report
(
"
current time %a
"
,
os
.
now
(
)
)
70
evohome
.
helpers
.
updatetemperatures
(
presets
)
71
end
72
if
arguments
.
auto
then
73
while
true
do
74
fetch
(
)
75
report
(
"
sleeping for %i seconds
"
,
delay
)
76
io
.
flush
(
)
77
os
.
sleep
(
delay
)
78
end
79
else
80
fetch
(
presets
)
81
end
82
else
83
report
(
"
invalid preset file
"
)
84
end
85
end
86 87
function
scripts
.
evohome
.
update
(
)
88
local
presets
=
arguments
.
presets
89
if
presets
then
90
presets
=
evohome
.
helpers
.
loadpresets
(
presets
)
91
end
92
if
presets
then
93
evohome
.
helpers
.
geteverything
(
presets
)
94
else
95
report
(
"
invalid preset file
"
)
96
end
97
end
98 99
function
scripts
.
evohome
.
server
(
)
100
local
presets
=
arguments
.
presets
101
if
presets
then
102
require
(
"
util-evo-imp-server
"
)
103
evohome
.
server
{
104
filename
=
presets
,
-- e:/domotica/code/evohome-presets.lua
105
host
=
arguments
.
host
,
106
port
=
tonumber
(
arguments
.
port
)
,
107
}
108
else
109
report
(
"
invalid preset file
"
)
110
end
111
end
112 113
if
environment
.
argument
(
"
collect
"
)
then
114
scripts
.
evohome
.
collect
(
)
115
elseif
environment
.
argument
(
"
update
"
)
then
116
scripts
.
evohome
.
update
(
)
117
elseif
environment
.
argument
(
"
server
"
)
then
118
scripts
.
evohome
.
server
(
)
119
elseif
environment
.
argument
(
"
exporthelp
"
)
then
120
application
.
export
(
environment
.
argument
(
"
exporthelp
"
)
,
environment
.
files
[
1
]
)
121
else
122
application
.
help
(
)
123
end
124