You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
var light = (client, clientId) => { |
|
|
|
var o = { |
|
state: false, |
|
LastOnTime: new Date().valueOf(), |
|
LastOffTime: new Date().valueOf(), |
|
LastSwiTime: 0, |
|
on: ()=>{ |
|
client.publish('hass/autoLight/'+clientId, '1'); |
|
}, |
|
off: ()=>{ |
|
client.publish('hass/autoLight/'+clientId, '0'); |
|
} |
|
|
|
}; |
|
|
|
|
|
client.on('message', (subject, msg)=>{ |
|
if(subject == 'hass/snsr/'+clientId+'/lightCtl'){ |
|
if(msg == 1) o.state = true; |
|
if(msg == 0) o.state = false; |
|
} |
|
if(subject == 'hass/snsr/'+clientId+'/light'){ |
|
if(msg == 1) o.state = true; |
|
if(msg == 0) o.state = false; |
|
} |
|
if(subject == 'hass/snsr/'+clientId+'/swi'){ |
|
o.LastSwiTime = new Date().valueOf(); |
|
} |
|
if(subject == 'hass/ctl/'+clientId+'/light'){ |
|
o.LastSwiTime = new Date().valueOf(); |
|
if(msg == 1) o.state = true; |
|
if(msg == 0) o.state = false; |
|
} |
|
}); |
|
|
|
|
|
|
|
return o; |
|
} |
|
|
|
|
|
exports.light = light;
|
|
|