Subversion Repositories HomeAutomation

Rev

Rev 1624 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1624 Rev 1625
1
 
1
 
2
RequireModule("irReceive");
2
RequireModule("irReceive");
3
RequireModule("irTransmit");
3
RequireModule("irTransmit");
4
RequireModule("Dimmer230");
4
RequireModule("Dimmer230");
5
 
5
 
6
var dimmer_module = GetModule("Dimmer230");
6
var dimmer_module = GetModule("Dimmer230");
7
var ir_module = GetModule("irReceive");
7
var ir_module = GetModule("irReceive");
8
 
8
 
9
function test_press(event, id, channel, data, protocol)
9
function test_press(event, id, channel, data, protocol)
10
{
10
{
11
    Log("Pressed: protocol=" + protocol + ", channel=" + channel + ", data=" + data);
11
    Log("Pressed: protocol=" + protocol + ", channel=" + channel + ", data=" + data);
12
   
12
   
13
    if (protocol == "NEC" && data == 3877174275)
13
    if (protocol == "NEC" && data == 3877174275)
14
    {
14
    {
15
        Dimmer230_StartFade(2, 0, 135, "Increase");
15
        Dimmer230_StartFade(2, 0, 135, "Increase");
16
        Dimmer230_StartFade(1, 0, 135, "Increase");
16
        Dimmer230_StartFade(1, 0, 135, "Increase");
17
    }
17
    }
18
    else if (protocol == "NEC" && data == 3860462595)
18
    else if (protocol == "NEC" && data == 3860462595)
19
    {
19
    {
20
        Dimmer230_StartFade(2, 0, 135, "Decrease");
20
        Dimmer230_StartFade(2, 0, 135, "Decrease");
21
        Dimmer230_StartFade(1, 0, 135, "Decrease");
21
        Dimmer230_StartFade(1, 0, 135, "Decrease");
22
    }
22
    }
23
    else if (protocol == "NEC" && data == 4144561155)
23
    else if (protocol == "NEC" && data == 4144561155)
24
    {
24
    {
25
        irTransmit_SendCode(1, 0, "Burst", "NEC", 3843720570);
25
        irTransmit_SendCode(1, 0, "Burst", "NEC", 3843720570);
26
    }
26
    }
27
    else if (protocol == "NEC" && data == 4211407875)
27
    else if (protocol == "NEC" && data == 4211407875)
28
    {
28
    {
29
        irTransmit_SendCode(1, 0, "Burst", "NEC", 3827008890);
29
        irTransmit_SendCode(1, 0, "Burst", "NEC", 3827008890);
30
    }
30
    }
31
}
31
}
32
 
32
 
33
function test_release(event, id, channel, data, protocol)
33
function test_release(event, id, channel, data, protocol)
34
{
34
{
35
    Log("Released: protocol=" + protocol + ", channel=" + channel + ", data=" + data);
35
    Log("Released: protocol=" + protocol + ", channel=" + channel + ", data=" + data);
36
   
36
   
37
    if (protocol == "NEC" && (data == 3877174275 || data == 3860462595))
37
    if (protocol == "NEC" && (data == 3877174275 || data == 3860462595))
38
    {
38
    {
39
        Dimmer230_StopFade(2, 0);
39
        Dimmer230_StopFade(2, 0);
40
        Dimmer230_StopFade(1, 0);
40
        Dimmer230_StopFade(1, 0);
41
    }
41
    }
42
    else if (protocol == "NEC" && (data == 4144561155 || data == 4211407875))
42
    else if (protocol == "NEC" && (data == 4144561155 || data == 4211407875))
43
    {
43
    {
44
        //irTransmit_SendCode(1, 0, "Released", "NEC", data);
44
        //irTransmit_SendCode(1, 0, "Released", "NEC", data);
45
    }
45
    }
46
}
46
}
47
 
47
 
48
function test_status(event, id, available)
48
function test_status(event, id, available)
49
{
49
{
50
    //Log("status change!");
50
    //Log("status change!");
51
}
51
}
52
 
52
 
53
ir_module.Bind("onStatusChange", test_status);
53
ir_module.Bind("onStatusChange", test_status);
54
ir_module.Bind("onPressed", test_press);
54
ir_module.Bind("onPressed", test_press);
55
ir_module.Bind("onReleased", test_release);
55
ir_module.Bind("onReleased", test_release);
56
 
56
 
57
 
57
 
58
/*CreateModuleAlias("bardisk", "Dimmer230", 2, { "channel" : 0 });
58
/*CreateModuleAlias("bardisk", "Dimmer230", 2, { "channel" : 0 });
59
CreateModuleAlias("bokhylla", "Dimmer230", 1, { "channel" : 0 });
59
CreateModuleAlias("bokhylla", "Dimmer230", 1, { "channel" : 0 });
60
CreateModuleAliasGroup("vardagsrum", [ "bokhylla", "bardisk" ]);
60
CreateModuleAliasGroup("vardagsrum", [ "bokhylla", "bardisk" ]);
61
*/
61
*/
62
 
62
 
63
function fadeto(alias, level, speed)
63
function fadeto(alias, level, speed)
64
{
64
{
65
    var alias_data = resolvealias(alias);
65
    var alias_data = resolvealias(alias);
66
   
66
   
67
    if (alias_data == null)
67
    if (alias_data == null)
68
    {
68
    {
69
        return "No such module name found";
69
        return "No such module name found";
70
    }
70
    }
71
   
71
   
72
    if (alias_data["is_group"])
72
    if (alias_data["is_group"])
73
    {
73
    {
74
        var result = "";
74
        var result = "";
75
       
75
       
76
        for (var n = 0; n < alias_data["aliases"].length; n++)
76
        for (var n = 0; n < alias_data["aliases"].length; n++)
77
        {
77
        {
78
            result += fadeto(alias_data["aliases"][n], level, speed) + "\n";
78
            result += fadeto(alias_data["aliases"][n], level, speed) + "\n";
79
        }
79
        }
80
       
80
       
81
        return result;
81
        return result;
82
    }
82
    }
83
   
83
   
84
    if (alias_data["module_name"] != "Dimmer230")
84
    if (alias_data["module_name"] != "Dimmer230")
85
    {
85
    {
86
        return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are Dimmer230";
86
        return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are Dimmer230";
87
    }
87
    }
88
   
88
   
89
    if (!speed)
89
    if (!speed)
90
    {
90
    {
91
        speed = 135;
91
        speed = 135;
92
    }
92
    }
93
 
93
 
94
    return Dimmer230_AbsoluteFade(alias_data["module_id"], alias_data["extra"], speed, level);
94
    return Dimmer230_AbsoluteFade(alias_data["module_id"], alias_data["extra"], speed, level);
95
}
95
}
96
RegisterConsoleCommand(fadeto, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableNames(), [ 0, 50, 100, 150, 200, 255 ], [ 50, 135, 200, 255 ]); });
96
RegisterConsoleCommand(fadeto, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableNames(), [ 0, 50, 100, 150, 200, 255 ], [ 50, 135, 200, 255 ]); });
97
 
97
 
98
function irsend_autocomplete(args)
98
function irsend_autocomplete(args)
99
{
99
{
100
    // args[0] == command name
100
    // args[0] == command name
101
    var arg_index = args.length - 2;
101
    var arg_index = args.length - 2;
102
   
102
   
103
    if (arg_index == 0)
103
    if (arg_index == 0)
104
    {
104
    {
105
        return irTransmit.instance_.GetAvailableNames();
105
        return irTransmit.instance_.GetAvailableNames();
106
    }
106
    }
107
    else if (arg_index == 1)
107
    else if (arg_index == 1)
108
    {
108
    {
109
        var remotes = Storage_GetParameters("RemoteList");
109
        var remotes = Storage_GetParameters("RemoteList");
110
       
110
       
111
        var result = new Array();
111
        var result = new Array();
112
       
112
       
113
        for (var name in remotes)
113
        for (var name in remotes)
114
        {
114
        {
115
            result.push(name);
115
            result.push(name);
116
        }
116
        }
117
       
117
       
118
        return result;
118
        return result;
119
    }
119
    }
120
    else if (arg_index == 2)
120
    else if (arg_index == 2)
121
    {
121
    {
122
        var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index]);
122
        var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index]);
123
 
123
 
124
        var buttons = Storage_GetParameters(remote_storage_name);
124
        var buttons = Storage_GetParameters(remote_storage_name);
125
 
125
 
126
        var result = new Array();
126
        var result = new Array();
127
       
127
       
128
        for (var name in buttons)
128
        for (var name in buttons)
129
        {
129
        {
130
            result.push(name);
130
            result.push(name);
131
        }
131
        }
132
       
132
       
133
        return result;
133
        return result;
134
    }
134
    }
135
   
135
   
136
    return new Array();
136
    return new Array();
137
}
137
}
138
 
138
 
139
 
139
 
140
function irsend(alias, remote, button)
140
function irsend(alias, remote, button)
141
{
141
{
142
    var alias_data = resolvealias(alias);
142
    var alias_data = resolvealias(alias);
143
   
143
   
144
    if (alias_data == null)
144
    if (alias_data == null)
145
    {
145
    {
146
        return "No such module name found";
146
        return "No such module name found";
147
    }
147
    }
148
   
148
   
149
    if (alias_data["is_group"])
149
    if (alias_data["is_group"])
150
    {
150
    {
151
        var result = "";
151
        var result = "";
152
       
152
       
153
        for (var n = 0; n < alias_data["aliases"].length; n++)
153
        for (var n = 0; n < alias_data["aliases"].length; n++)
154
        {
154
        {
155
            result += irsend(alias_data["aliases"][n], remote, button) + "\n";
155
            result += irsend(alias_data["aliases"][n], remote, button) + "\n";
156
        }
156
        }
157
       
157
       
158
        return result;
158
        return result;
159
    }
159
    }
160
   
160
   
161
    if (alias_data["module_name"] != "irTransmit")
161
    if (alias_data["module_name"] != "irTransmit")
162
    {
162
    {
163
        return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are irTransmit";
163
        return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are irTransmit";
164
    }
164
    }
165
   
165
   
166
    Log(remote);
-
 
167
    var remote_storage_name = Storage_GetParameter("RemoteList", remote);
166
    var remote_storage_name = Storage_GetParameter("RemoteList", remote);
-
 
167
   
168
    Log(remote_storage_name);
168
    if (!remote_storage_name)
-
 
169
    {
-
 
170
        return "No such remote name in list, " + remote;
-
 
171
    }
-
 
172
   
169
    var button = eval("(" + Storage_GetParameter(remote_storage_name, button) + ")");
173
    var button_string = Storage_GetParameter(remote_storage_name, button);
-
 
174
   
-
 
175
    if (!button_string)
-
 
176
    {
-
 
177
        return "No such button " + button + " found on remote " + remote;
-
 
178
    }
-
 
179
   
-
 
180
    var button = eval("(" + button_string + ")");
-
 
181
   
170
    Log(JSON.stringify(button));
182
    Log(JSON.stringify(button));
171
    Log(alias_data["module_id"]);
183
    Log(alias_data["module_id"]);
172
    Log(alias_data["extra"]);
184
    Log(alias_data["extra"]);
173
    Log(button["protocol"]);
185
    Log(button["protocol"]);
174
    Log(button["data"]);
186
    Log(button["data"]);
175
   
187
   
176
    return irTransmit_SendCode(alias_data["module_id"], alias_data["extra"], "Burst", button["protocol"], button["data"]);
188
    return irTransmit_SendCode(alias_data["module_id"], alias_data["extra"], "Burst", button["protocol"], button["data"]);
177
}
189
}
178
RegisterConsoleCommand(irsend, irsend_autocomplete);
190
RegisterConsoleCommand(irsend, irsend_autocomplete);
-
 
191
 
-
 
192
 
-
 
193
function media(mode)
-
 
194
{
-
 
195
    if (!mode)
-
 
196
    {
-
 
197
        return "You must specify a mode";
-
 
198
    }
-
 
199
   
-
 
200
    if (mode == "movie")
-
 
201
    {
-
 
202
        irsend("tvbankut", "Yamaha_RAV34", "POWER");
-
 
203
       
-
 
204
        fadeto("bokhylla", 100, 135);
-
 
205
        fadeto("bardisk", 0, 135);
-
 
206
 
-
 
207
        sleep(1000);
-
 
208
        irsend("tvbankut", "Yamaha_RAV34", "CD");
-
 
209
    }
-
 
210
    else if (mode == "tv")
-
 
211
    {
-
 
212
        irsend("tvbankut", "Yamaha_RAV34", "POWER");
-
 
213
       
-
 
214
        fadeto("bokhylla", 150, 135);
-
 
215
        fadeto("bardisk", 150, 135);
-
 
216
 
-
 
217
        sleep(1000);
-
 
218
        irsend("tvbankut", "Yamaha_RAV34", "DTV_CBL");
-
 
219
    }
-
 
220
    else if (mode == "off")
-
 
221
    {
-
 
222
        irsend("tvbankut", "Yamaha_RAV34", "STANDBY");
-
 
223
       
-
 
224
        fadeto("bokhylla", 0, 135);
-
 
225
        fadeto("bardisk", 0, 135);
-
 
226
    }
-
 
227
   
-
 
228
    return "OK";
-
 
229
}
-
 
230
RegisterConsoleCommand(media, function(args) { return StandardAutocomplete(args, [ "off", "tv", "movie" ]); });
179
 
231