Jump to content
NOTICE / HINWEIS: iOS 18 Update and Today Widgets ×

Schalten nach Wetter-Temperatur


Beagel

Recommended Posts

Hallo zusammen,

ich Versuche mich an meinem ersten Script, 

der Schalter_Brunnen soll bei +30°C angehen und unter +27°C ausbleiben. Hab mir dazu das Beispiel Script von GitHub: turn-on-weather.js genommen und mit nach meinen Daten verändert. Siehe Script: Home= mein Ort, API hab ich auch

// Copyright 2021 Allterco Robotics EOOD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Shelly is a Trademark of Allterco Robotics

// Shelly Script example: Turn on when temperature is below CONFIG.tempBelowTurnOn
// Turn off when temperature is above CONFIG.tempAboveTurnOff
// For getting an API-KEY from Accuweather follow the instructions on their site
// for registering a new application, copy the key and paste it here

let CONFIG = {
  accuWeatherAPIKEY: "API-Accuweather",
  weatherForecastEndpoint:
    "http://dataservice.accuweather.com/forecasts/v1/daily/1day/",
  weatherCurrentEndpoint:
    "http://dataservice.accuweather.com/currentconditions/v1/",
  locations: {
    Home: xxxxx,
  },
  //check every 60 seconds
  checkInterval: 60 * 1000,
  tempAboveTurnOn: -1,
  tempBelowTurnOff: 0,
};

function getWeatherURLForLocation(location) {
  return (
    CONFIG.weatherCurrentEndpoint +
    JSON.stringify(CONFIG.locations[location]) +
    "?apikey=" +
    CONFIG.accuWeatherAPIKEY +
    "&details=false"
  );
}

function activateSwitch(activate) {
  Shelly.call(
    "Switch.Set",
    { id : 0, on: true },
    function (response, error_code, error_message) {}
  );
}

function TemperatureControlLocation(location) {
  Shelly.call(
    "http.get",
    { url: getWeatherURLForLocation(location) },
    function (response, error_code, error_message, location) {
      let weatherData = JSON.parse(response.body);
      if (weatherData[0].Temperature.Metric.Value <= CONFIG.tempBelowTurnOn) {
        activateSwitch(true);
      }
      if (weatherData[0].Temperature.Metric.Value >= CONFIG.tempAboveTurnOff) {
        activateSwitch(false);
      }
      print(
        location,
        " Temperature - ",
        weatherData[0].Temperature.Metric.Value,
        "deg C"
      );
    },
    location
  );
}

//TemperatureControlLocation("Home");

Timer.set(CONFIG.checkInterval, true, function () {
  console.log("Checking weather");
  TemperatureControlLocation("Home");
});

wenn ich das so aus führe bekomme ich im Log:

Checking weather.                                        13:40:05
Home Temperature - 25.3 deg C

ändere ich zum Testen:

  tempAboveTurnOn: 30,
  tempBelowTurnOff: 27

kommt als Fehler:

Checking weather.                                                                                     13:48:03
Uncaught Error: Cannot read property 'Temperature' of undefined      13:48:04
at if (weatherData[1].Temperature.Metric.Value >= CONFIG....              13:48:04
^
                                                                                                                      13:48:04
in function called from system,

und es wird nichts geschaltet, muss ich irgendwo noch etwas angeben ? Was ist mit id gemeint in:

Shelly.call(
    "Switch.Set",
    { id : 0, on: true },

 

Im Vorraus schon mal Danke für Eure Ideen und Hilfe

Gruß Beagel

Link to comment
Share on other sites

Welche accuWeatherAPIKEY - Lizense hast du?

Die "Free" wäre nach 50 calls oder 50 Minuten am Tag in deinem Script, für einen Tag gesperrt.

image.thumb.png.44b82e0348cb34473b4a5dade23a1c4a.png

Es gibt Shelly's mit unterschiedlich vielen Relais oder Outputs.

Mit "id = 0" sprichst du das erste und mit "id = 1" das zweite an. [0..7] bei den X-Modulen.

 

 

Edited by Hummelchen
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...