Homey Community Forum

HomeyScript App

I have found a workaround - Homeyscript only sets a variable and a second flow reacts to the change of the variable and does what I need.

How do you set a variable with Homeyscript? Can’t seem to find that in the docs…

I am still using BetterLogic variables, an example script can be found in this topic: https://forum.athom.com/discussion/3666/homeyscript-share-your-scripts-main-discussion-topic/p2

(just search for “betterlogic”)

1 Like

With version 1.5 you could set a variable with setTagValue

let dayOfYear = testDay.getDayOfYear();
await setTagValue(name, {type: "number", title: "CV_On_Day"}, dayOfYear ); 

With version 2.0 you’ll receive a Script Error: Cannot set value, token is not registered

1 Like

Wait, Go in the app to More, Logic, then create variable.
Then you can use it in HomeyScript with setTagValue
:beers:

nope, using await setTagValue("listalarm", {type: "text", title: "listalarm"}, sum); returns an error, without the await it just doesn’t set the value in the variable. :cry:

Darn, I guess it’s just broken.

I did send a request to Athom for not being able to restart apps in HomeyScript. HomeyScript generates an error: You have no access to do this.

Homey.apps.restartApp({id: 'nl.scanno.mqtt'});

Hello I am a complete new to this so I try copy modify I found an example on a old forum but then when tested I got measure_battery undefined.
Is it possible to get a copy of your script?’
how to find what data that can be found?
on https://developer.athom.com/docs/api/HomeyAPI.ManagerDevices.Device.html
I found some general data that could be found but not battery status

Here is a sniplet which logs battery status for all devices (works with Homey 2.x for me):

let devices = await Homey.devices.getDevices();

const MEASURE_BATTERY = 'measure_battery';
const ALARM_BATTERY = 'alarm_battery';

function logBatteryLevels() {
    _.forEach(devices, device => {
        if (device.capabilitiesObj[MEASURE_BATTERY]) {
            console.log(`Device ${device.name} has battery level: ${device.capabilitiesObj[MEASURE_BATTERY].value}`);       
        } if (device.capabilitiesObj[ALARM_BATTERY]) {
            console.log(`Device ${device.name} has ${device.capabilitiesObj[ALARM_BATTERY].value ? 'battery alarm' : 'no battery alarm'}`);            
        }
    });
}
1 Like

thanks Volkov now I just need to understand it I got an error because of measure null and after put in a consol log I found that it was two unit that diden’t exist in reality it had a problem with.
question how can one found out the capoability of a device?
for examle as simple as temp on a xiaomi device.

You should have all the capabilities with their current values in device.capabilitiesObj. Try to log that to the console for your device and you will see the values.

A device that is not ready will not have a capabilitiesObj and can very well cause the error.

Now it feels a lot better a real jumpstart to get all capabilities. thanks for a fast response.
add my smsall program that list all devices capabilities
// list capabilityes
let devices = await Homey.devices.getDevices();

Object.values(devices).forEach(device => {
//write out name of device and all the capabilities
console.log(device.name, device.capabilitiesObj);
});

To use logic variabels you use code like this
let Logic = await Homey.logic.getVariables()
console.log(Logic);

updateVariable

await Homey.logic.updateVariable({id: yourid, variable: yourVar})

You have access to the API https://developer.athom.com/docs/api
so Homey.whatyouwannareach gives alot of options. send me a question if you need more help.

1 Like

How do I get the id if I only know the name of the variable?

Use get function and console log it. That will give you the I’d

let devices = await Homey.devices.getDevices();
_.forEach(devices, device => {
console.log(device.name, ’ ',device.id);
});

This is for devices. Need this for logic variables.

@gagga Sorry, I did not read well, but how about this:

Did you try this?

Or go to: https://developer.athom.com/tools/api-playground
and add a new line: Homey.logic.getVariables(); and press Run :blush:

1 Like

Hi.

Does the HomeyScript “Run a script with an argument” (in Flow) support passing multiple arguments or only one?

Thank you.