Highest and lowest outdoors temperature during day

I want to receive a push message with the maximum and minimum temperature during the last day. This temp sensor is outdoors. I don’t get it done. I receive same temp for both max and minimum temp. So i think when the temp becomes higher this will set max temp. when temp becomes lower, this will set minimum temp. Can anyone show me with example flow what to do.? Using logica(type) etc. Thanks

What is during the last day?

And what did u try? Can u show us some screenies of the flows u tried and not working?

This is the way I do it. Every night I reset these values with a flow.

This does it for me.
This flow sets the minimum temperature of the day

This sets the max temperature of the day

This sends a message to a user and resets the variables.

I use it to tell the time and temperature of max and min temp in our greenhouse.

Kind regards.

Bo

1 Like

Thanks gonna give it a try

Thanks for this! Works like a charm!

For the ones not so familiar with logic: add the Drivhus:mintemp (or greenhouse:mintemp or kas:mintemp) as a text/string variable (or with the app Better Logic). Once you have added the string it can be used as a tag in a flow.

I have exactly this use case, but instead of triggering a flow on each temparature change, I have created a HomeyScript. This HomeyScript calculates the min and max temperature based on the log from Insights.

My script:

let MinVarName="MinTemp"; 
let MaxVarName="MaxTemp";

//uri = tuinsensor(Philips Hue)
//id = temperatuur
let entries = await Homey.insights.getLogEntries({uri: "homey:device:3245df43-c818-2289-98c6-ec033472dbf3", 
                                            id: "measure_temperature",
                                            resolution: "last24Hours"});

//console.log(entries);

var lowest = Number.POSITIVE_INFINITY;
var highest = Number.NEGATIVE_INFINITY;
var tmp;
for (var i=entries.values.length-1; i>=0; i--) {
    tmp = entries.values[i].v;
    if (tmp != null && tmp < lowest) {
        lowest = tmp;
    }
    if (tmp != null && tmp > highest){ 
        highest = tmp;
    }
}
console.log("Max: " + highest + " Min: " + lowest);

await setTagValue(MinVarName, {type: "number", title: MinVarName}, lowest ); 
await setTagValue(MaxVarName, {type: "number", title: MaxVarName}, highest ); 

return true;

Every morning I run this script from a flow and then the flow updates two variables with the min and max temperature.

5 Likes

Hi. This is almost what I want. Pasted the code in a new script and run it and it fails on line #1 for

“let MinVarName=“MinTemp”;”

SyntaxError: Invalid or unexpected token

I’m not smart enough to spot the errors, but just smart enough to foresee that I might need a different ID for my device providing the temperatuers (Telldus Weather Station)?

Is that correct? How do I find the ID to use? Is it a given that I find the temperatures in the same attibute (entries.values[i].v)?

Thanks.

Try it again now that I changed the post, as the post converted all double quotes to so called “smart quotes” which are an invalid character.

1 Like

Super, now it works passed line 2 :-), but now it fails on the ID I think.
Here’s the error.

❌ Script Error
⚠️ Not Found: Log with ID measure_temperature: Not Found: Log with ID measure_temperature
    at /app/node_modules/athom-api/dist/index.js:1:1247257
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Hi,
You cannot use the device ID from an other users’ script, you have to look up the ID for your variable to make it work :wink:
This works for me:
!! Forget the code below, it’s for Logics variables, not for devices :face_with_open_eyes_and_hand_over_mouth:

// Retrieve a Variable ID
//
// Replace varName with your var name
let varName = "my_temperature_variable"
// end of user input
const logicVars = await Homey.logic.getVariables()
for (var iLogicVar in logicVars){
  if (logicVars[iLogicVar].name == varName)
  log("Variable: " + logicVars[iLogicVar].name + "\nValue: " + logicVars[iLogicVar].value + "\nID: " + logicVars[iLogicVar].id)
}

Yepp, I guessed that all along Peter_Kawa. I’m just a little at loss on how to find the ID. Any suggestions? :slight_smile:

From my first post:
image

In my quest to get this script working, I’ve drafted this piece of code (part of a bigger loop on devices):

   if (device.name=="Utetemp") {
     log(`\n${device.class}:\t${device.name}\nID:\t${device.id}\nDriver:\t${device.driverId}`);
     for (const capability of Object.values(device.capabilitiesObj)) {
       log(`${capability.title}:\t${capability.value}\t${capability.id}`);
     }
   }

Which outputs:

 sensor: Utetemp
 ID: 0a81e149-e8ff-4452-b6ba-c73537a9f52a
 Driver: homey:app:com.weather-sensors:temphum
 Battery alarm: false alarm_battery
 Humidity: 82 measure_humidity
 Temperature: 16.5 measure_temperature

Which reveals the ID and verifies the property. I’ve inserted the ID, but still the code fails with this message:

 ❌ Script Error
 ⚠️ Not Found: Log with ID measure_temperature: Not Found: Log with ID measure_temperature

If I just read this, it’s like there’s no entries with temperatures from that device in Insights. But I can indeed view the history values there:

What’s the next thing I should investigate?

Oh wait, my bad, I was out of coffee appearantly :face_with_peeking_eye:
Logics variables are not the same as device tags like measure_temperature so forget my post pls.

Found the culprit:
The let entries = line should be one long line. The script of Tycho had new line and tabs in it somehow:

This code works with the right device ID:

// retreive_insights_value.js

let MinVarName="MinTemp"; 
let MaxVarName="MaxTemp";

//uri = Temp Koelkast (Aqara weather sensor)
//id = temperatuur
let entries = await Homey.insights.getLogEntries({uri: "homey:device:715639e1-817b-4af1-97ac-955733a02569", id: "measure_temperature", resolution: "last24Hours"});

// To check
//console.log("All insights values of last 24h", entries);

var lowest = Number.POSITIVE_INFINITY;
var highest = Number.NEGATIVE_INFINITY;
var tmp;
for (var i=entries.values.length-1; i>=0; i--) {
    tmp = entries.values[i].v;
    if (tmp != null && tmp < lowest) {
        lowest = tmp;
    }
    if (tmp != null && tmp > highest){ 
        highest = tmp;
    }
}

await tag(MinVarName, lowest); 
await tag(MaxVarName, highest); 

console.log("Temp Koelkast: \nMax: " + highest + "°C\nMin: " + lowest + "°C");
return true;

Note the creating/updating of HS tags (await tag(name, var) is different (“simplyfied”) nowadays!



Script output:


And the HS tags are available, see [MaxTemp] and [MinTemp] :
Screenshot_15

2 Likes

Am not sure what’s not working at my end, but the output’s the same. Paste your script, subst the ID and run. It fails on the let entries = … call ang gives the same message as earlier:

:x: Script Error
:warning: Not Found: Log with ID measure_temperature: Not Found: Log with ID measure_temperature
at /app/node_modules/athom-api/dist/index.js:1:1247257
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Did you try with an other sensor or capability? I can’t reproduce your exact error by crippling the ID or the capability. In those cases it’s:


———————————————————
❌ Script Error

⚠️ log_not_found: Could not find that Log
    at /node_modules/athom-api/dist/index.js:1:1247257
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

(note my error lacks /app in front of /node_modules/ath......)

Wait, are you using a Pro 2023?
Change the resolution to yesterday and test the script pls?

1 Like

Yes, this runs on a Homey Pro 2023. Tried with yesterday:
let entries = await Homey.insights.getLogEntries({uri: “homey:device:0a81e149-e8ff-4452-b6ba-c73537a9f52a”, id: “measure_temperature”, resolution: “yesterday”});

…but it yielded the same results:

:x: Script Error
:warning: Not Found: Log with ID measure_temperature: Not Found: Log with ID measure_temperature
at /app/node_modules/athom-api/dist/index.js:1:1247257
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Just tried with another device, a SONOS speaker.

//uri = SONOS Living Room, 5de31c51-771b-46e7-9ed1-5699e9ab8ed9 (homey:app:com.sonos:cloud)
//id = speaker_duration
let entries = await Homey.insights.getLogEntries({uri: "homey:device:5de31c51-771b-46e7-9ed1-5699e9ab8ed9", id: "speaker_duration", resolution: "yesterday"}); //last24Hours

Was it a success? Not so much :slight_smile:

❌ Script Error
⚠️ Not Found: Log with ID speaker_duration: Not Found: Log with ID speaker_duration
    at /app/node_modules/athom-api/dist/index.js:1:1247257
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Is it likely that my method of discovering IDs and capabilities is WAAAAAAY off? This is how I do it (for each device):

    log(`\n${device.class}:\t${device.name}\nID:\t${device.id}\nDriver\t${device.driverId}`);
    for (const capability of Object.values(device.capabilitiesObj)) {
      log(`${capability.title}:\t${capability.value}\t${capability.id}`);
    }

This outputs among a lots of stuff this:

speaker: Living Room
ID: 5de31c51-771b-46e7-9ed1-5699e9ab8ed9
Driver: homey:app:com.sonos:cloud
Duration: 449 speaker_duration

Hmmmm I’m starting to think things work slightly different on the 2023 model…

Yes you can check @ https://tools.developer.homey.app/tools/devices and search for your device to doublecheck the ID and capabilities
Your script and result looks good to me.

Feel free to try this script, but I doubt the results will differ

// Enter the deviceName
let deviceName = "Temp Koelkast"
//
const myDevices = await Homey.devices.getDevices();
for (var iMyDevice in myDevices){
  if (myDevices[iMyDevice].name == deviceName) {
  log(`Device:\t ${myDevices[iMyDevice].name} \nZone:\t ${myDevices[iMyDevice].zoneName}\nID:\t ${myDevices[iMyDevice].id} \nCapabilities: ${myDevices[iMyDevice].capabilities}`)
  }
};
if (deviceName == "") {
  return false
} else {
  return true;
}


Jeroen, @Jero

Sorry to bother you, but you might have a clue why this code errors on a Pro 2023 and runs fine on a Pro 2019?

let entries = await Homey.insights.getLogEntries({uri: "homey:device:715639e1-817b-4af1-97ac-955733a02569", id: "measure_temperature", resolution: "last24Hours"});


Error: