Homey Community Forum

Grøn energi .. og visning i HOMEY

Hej er ved at kigge på hvordan jeg får HOMEY til at vise hvor meget grøn energi der er i stikkontakten…

Derfor har jeg lavet nedenstående HOMEYSCRIPT ( det er kun et MOCKUP SÅ MEGET GRIM KODE)

Den kaldes så via et flow of så kan man bruge variablen GreenEnergyPercent…

Tænker at enten skal det bruges i LED RING eller LOGIC ZDB kontakt

// ENERGINET

/*

// Get the body JSON
const body = await res.json();
//log(${body.result.records[1].PriceArea});
//log(${body.result.records[1].HourDK});
//log(${body.result.records[1].OnshoreWindPower});

// Log the services
body.result.records.forEach(records => {
if(records.PriceArea==‘DK1’){// ONLY WEST DK ELSE USE DK2
if(records.OnshoreWindPower!=null){ //ONLY use where data
//log(${records.HourDK}: ${(records.OnshoreWindPower +records.SolarPower + records.OffshoreWindPower)/records.TotalLoad*100});
if(records.HourDK.substring(11,13)>TimeSlot || records.HourDK.substring(8,10)<DateSlot ){ //make sure newest timeslot ( also at day shift)
//log(‘NEWEST’)
GreenEnergyPercent= (records.OnshoreWindPower +records.SolarPower + records.OffshoreWindPower)/records.TotalLoad*100;
}
//log(records.HourDK.substring(11,13));
TimeSlot=records.HourDK.substring(11,13);
DateSlot=records.HourDK.substring(8,10);
}}
});
global.set(‘GreenEnergyPercent’, GreenEnergyPercent);
//Log(global.get(‘LysStue’));

//set tag
await setTagValue(‘GreenEnergyPercent’, {type:‘number’, title: ‘GreenEnergyPercent’}, GreenEnergyPercent );

return(true);