I would need to create function allowing me to change values on devices. Continued trials on on below topic
[Setting Logic Variable by HomeyScript - #53 by Eko_taas]
Example of myDevice (only part of actual AVD)
“_HiidenSite”: {
“devicecapabilities_text-custom_12.text6”: {
“title”: “currentOutTemp”,
“value”: -17.1
},
…
}
as wanted to use more title instead of cabability, made this code for testing reading by title (and working fine):
> const devices = await Homey.devices.getDevices();
>
> const sensorName = "_HiidenSite";
> const capabilityTitle = "currentOutTemp";
>
> for (const device of Object.values(devices)) {
> if (device.name === sensorName) {
> for (const capability of Object.values(device.capabilitiesObj)) {
> if (capability.title === capabilityTitle) {
> return capability.value; // Return the capability value (even if it's null)
> }
> }
> return -1000; // Indicate capability title not found for the sensor
> }
> }
> return -2000; // Indicate sensor not found
Now wanted to create code to update device value by title… but could only get working within script
//async function setSensorValueByTitle(sensorName, capabilityTitle, newValue) {
// Get all devices
const devices = await Homey.devices.getDevices();
const sensorName = "_HiidenSite";
const capabilityTitle = "currentOutTemp";
const newValue = -18.1;
for (const device of Object.values(devices)) {
if (device.name === sensorName) {
for (const capability of Object.values(device.capabilitiesObj)) {
if (capability.title === capabilityTitle) {
capability.value = newValue; // Update the capability value with the new value
device.capabilitiesObj.value = newValue
return newValue;
}
}
return -1000; // Indicate capability title not found for the sensor
}
}
return -2000; // Indicate sensor not found
//}
Was not able to figure out how to modify this to get it to Homey-level (and not only till this script)
device.capabilitiesObj.value = newValue
On earlier mentioned topic can see how to do that for variable, but what to do with when device?
Thanks in advance for any help…