Skip to content

Commit

Permalink
Merge pull request #12 from ksjoberg/add-current-power-condition
Browse files Browse the repository at this point in the history
Add condition to check if measured power is in range
  • Loading branch information
yhaugom authored Dec 20, 2018
2 parents 149882c + 0101d2c commit e6f416b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ class telldusApp extends Homey.App {

onInit() {

let currentPowerCondition = new Homey.FlowCardCondition('current_power');
currentPowerCondition
.register()
.registerRunListener(( args, state ) => {
var power = args.my_device.getCapabilityValue('measure_power');
var margin = args.W * args.errormargin / 100;

if ((power >= args.W - margin) && (power < args.W + margin))
{
return Promise.resolve( true );
}

return Promise.resolve( false );
});

this.log('${Homey.manifest.id} is running...');

}
Expand Down
39 changes: 39 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,45 @@
"large": "/assets/images/large.png",
"small": "/assets/images/small.png"
},
"flow": {
"triggers": [],
"actions": [],
"conditions": [
{
"id": "current_power",
"title": {
"en": "The current power usage"
},
"args": [
{
"name": "my_device",
"type": "device",
"filter": "driver_id=TZWP-102"
},
{
"name": "W",
"type": "number",
"min": 0,
"max": 2300,
"step": 10,
"placeholder": {
"en": "Set a value in watts"
}
},
{
"name": "errormargin",
"type": "number",
"min": 0,
"max": 100,
"step": 10,
"placeholder": {
"en": "Set error margin in %"
}
}
]
}
]
},
"drivers": [
{
"id": "TZDW-100",
Expand Down

0 comments on commit e6f416b

Please sign in to comment.