Was haltet ihr hiervon:
Habe das mit einem Plus 1 PM und einem Schalter simuliert. Sollte auf dem Pro des TE auch laufen.
Voraussetzung: Shelly hat Internetverbindung und Switches sind physikalisch eins zu eins zugeordnet.
Inputs sind Mode Switch und detached. Außerdem verhindert es, dass die BWM das Licht vor Sonnenuntergang, also tagsüber, einschalten. Funktioniert also auch ohne Luxsensor im BWM.
In der Config kann man die Endzeit eintragen z.b. 22:00. Alles zwischen Sonnenuntergang und 23:59 ist zulässig.
Das Skript macht genau das, was du wolltest. Der BWM kann die scheduled auf ON gesetzten Outputs nicht ausschalten.
Scripts -> Add script -> Name vergeben (z.B. BWMAstro)-> das u.g. Skript dort hinein kopieren -> Save -> Start.
Wenn du später willst, dass das Skript nach dem Booten startet, den Schiebeschalter für das Skript auf on.
Bugfix Stand 01.08.23 04:09 Uhr
let Config = {
//any time between sunset and 00:00
endtime: '22:00'
}
function get_minute() {
let time = Shelly.getComponentStatus("sys").time;
return time.slice(time.indexOf(":") + 1 ,time.length);
}
function watch(){
if(get_minute() === '00'){
get_astro();
}
}
function get_pushes (e){
if(!e){
return;
}
if(e.info.event === "toggle" && e.name === "input"){
let id = e.id;
let state = e.info.state;
let on_off = 'Off';
if(state){
on_off = 'On';
}
print("Switch " + id +': ' + on_off);
let end = time_to_number(Config.endtime);
let now = time_to_number(Shelly.getComponentStatus("sys").time);
if(!state){
if(now >= sunset && now <= end){
print('Output ' + id + ': Off blocked');
return;
}
print("Output " + id + ': '+ on_off);
Shelly.call("Switch.set", {'id': id, 'on': state});
return;
}
if(state) {
last_min = time_to_number('23:59');
if(now >= sunset && now <= last_min) {
print("Output " + id + ': '+ on_off);
Shelly.call("Switch.set", {'id': id, 'on': state});
return;
}
if(now < sunrise){
print("Output " + id + ': '+ on_off);
Shelly.call("Switch.set", {'id': id, 'on': state});
return;
}
print('Output ' + id + ': On blocked');
}
}
}
function time_to_number(time){
let t = time.split(":");
let h = parseInt(t[0]);
let m = parseInt(t[1]);
return h * 3600 + m * 60;
}
function twelve_to_twentyfour(time){
t = time.split(":");
let h = parseInt(t[0]);
let m = parseInt(t[1]);
if(t[2].indexOf('PM') > -1){
h += 12;
}
let extra = '';
if(h < 10){
extra = '0';
}
return extra + h + ':' + m;
}
function get_astro(){
print('Try to get location...');
Shelly.call('sys.getConfig','',
function(result, error_code, error_message,action_type) {
if(error_code === 0) {
lon = result.location.lon;
lat = result.location.lat
print('Longutude: ' + lon);
print('Latitude: ' + lat);
url = "https://api.sunrisesunset.io/json?lat=" + lat + "&lng=" + lon;
print('Try to get astro data...');
Shelly.call('http.get', {url:url,timeout:15},
function(result, error_code, error_message,action_type) {
if(error_code === 0) {
let res = JSON.parse(result.body);
print('Sunrise: ' + twelve_to_twentyfour(res.results.sunrise));
print('Sunset : ' + twelve_to_twentyfour(res.results.sunset));
sunrise = time_to_number(res.results.sunrise.slice(0,res.results.sunrise.indexOf(' '))) ;
sunset = time_to_number(res.results.sunset.slice(0,res.results.sunset.indexOf(' ')));
sunset += 12 * 3600;
print('System ready');
}
}
);
}
}
);
}
let lon
let lat
let sunrise;
let sunset;
get_astro();
Shelly.addEventHandler(get_pushes);
Timer.set(60 * 1000,true,watch);
Alles anzeigen
Ausgabe sollte in etwa so aussehen:
04:06:24 Try to get location...
04:06:24 Longutude: 8.087301
04:06:24 Latitude: 53.579098
04:06:24 Try to get astro data...
04:06:33 Sunrise: 05:43
04:06:33 Sunset : 21:27
04:06:33 System ready
04:09:45 Switch 0: Off
04:09:45 Output 0: Off
04:09:48 Switch 0: On
04:09:48 Output 0: On
Alles anzeigen