Skip to content

Commit

Permalink
Daily rain capability removed, since always null for UDP API.
Browse files Browse the repository at this point in the history
Simplified logic for wind trigger conditions.
  • Loading branch information
WillooWisp committed Mar 5, 2019
1 parent dfd22ea commit 5a8e7c7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 88 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

Adds support for WeatherFlow's Smart Weather Station

First version, with quite limited functionality.
Upcoming versions will support more measurement values and flow triggers.

# Changelog

* 0.3.0 Flow triggers added for brightness above/below specified threshold.
* 0.2.1 Fixed bug in rain sensor reading. For some reason, the daily rain still reports no value using the WeatherFlow's UDP API.
* 0.2.0 Added more sensor readings on both Air and Sky devices. Air and Sky devices must be removed and added again in order for the new sensor readings to show up. Flow triggers and conditions added for rain started and wind above/below specified threshold.
* 0.1.1 Increased the time searching for Air and Sky devices when pairing.
Expand Down
86 changes: 36 additions & 50 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.weatherflow.smartweatherstation",
"version": "0.2.1",
"version": "0.3.0",
"compatibility": ">=1.5.0",
"sdk": 2,
"brandColor": "#3077BF",
Expand All @@ -11,7 +11,9 @@
"en": "Adds support for WeatherFlow's Smart Weather Station"
},
"tags": {
"en": [ "weatherflow smart weather temperature rain wind sensor" ]
"en": [
"weatherflow smart weather temperature rain wind sensor"
]
},
"category": [
"climate"
Expand All @@ -26,29 +28,14 @@
"email": "[email protected]"
},
"contributing": {
"donate": {
"paypal": {
"username": "willoowisp"
}
}
},
"donate": {
"paypal": {
"username": "willoowisp"
}
}
},
"homeyCommunityTopicId": 9816,
"capabilities": {
"measure_rain_day": {
"type": "number",
"title": {
"en": "Rain 24h"
},
"getable": true,
"setable": false,
"decimals": 0,
"units": {
"en": "mm"
},
"uiComponent": "sensor",
"uiQuickAction": false,
"icon": "/assets/measure_rain_day_capability.svg"
},
"measure_uv": {
"type": "number",
"title": {
Expand Down Expand Up @@ -131,18 +118,18 @@
},
"pair": [
{
"id": "list_devices",
"template": "list_devices",
"navigation": {
"next": "add_devices"
},
"options": {
"singular": false
}
"id": "list_devices",
"template": "list_devices",
"navigation": {
"next": "add_devices"
},
"options": {
"singular": false
}
},
{
"id": "add_devices",
"template": "add_devices"
"id": "add_devices",
"template": "add_devices"
}
]
},
Expand All @@ -154,11 +141,10 @@
"class": "sensor",
"capabilities": [
"measure_rain",
"measure_rain_day",
"measure_luminance",
"measure_wind_strength",
"measure_wind_angle",
"measure_wind_angle",
"measure_gust_strength",
"measure_luminance",
"measure_uv",
"measure_solarradiation",
"measure_voltage"
Expand All @@ -169,18 +155,18 @@
},
"pair": [
{
"id": "list_devices",
"template": "list_devices",
"navigation": {
"next": "add_devices"
},
"options": {
"singular": false
}
"id": "list_devices",
"template": "list_devices",
"navigation": {
"next": "add_devices"
},
"options": {
"singular": false
}
},
{
"id": "add_devices",
"template": "add_devices"
"id": "add_devices",
"template": "add_devices"
}
]
}
Expand Down Expand Up @@ -210,7 +196,7 @@
"type": "device",
"name": "sky",
"filter": "driver_id=sky"
},
},
{
"type": "range",
"name": "wind_speed",
Expand All @@ -232,7 +218,7 @@
"type": "device",
"name": "sky",
"filter": "driver_id=sky"
},
},
{
"type": "range",
"name": "wind_speed",
Expand Down Expand Up @@ -262,14 +248,14 @@
{
"id": "is_windy",
"title": {
"en": "It !{{is|isn't}} blowing heavy"
"en": "It !{{is|isn't}} windy"
},
"args": [
{
"type": "device",
"name": "sky",
"filter": "driver_id=sky"
},
},
{
"type": "range",
"name": "wind_speed",
Expand Down
54 changes: 19 additions & 35 deletions drivers/sky/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SkyDriver extends Homey.Driver {
async onPairListDevices(data, callback) {
await this._sleep(20000);

const airDevices = Homey.app.devices.filter(device => device.name.startsWith("SK"));
const skyDevices = Homey.app.devices.filter(device => device.name.startsWith("SK"));

// Required properties:
// "data": { "id": "abcd" },
Expand All @@ -28,7 +28,7 @@ class SkyDriver extends Homey.Driver {
// "store": { "foo": "bar" },
// "settings": { "my_setting": "my_value" },

callback(null, airDevices);
callback(null, skyDevices);
}

updateObservations(message) {
Expand Down Expand Up @@ -58,27 +58,22 @@ class SkyDriver extends Homey.Driver {
// Rain accumulated (mm)
const rain = values[3];
device.setCapabilityValue('measure_rain', rain).catch(this.error);
// Local Day Rain Accumulation (mm)
let dayRain = values[11];
if (!dayRain) {
dayRain = 0;
}
device.setCapabilityValue('measure_rain_day', dayRain).catch(this.error);
// Solar radiation: (W/m^2)
device.setCapabilityValue('measure_solarradiation', values[10]).catch(this.error);
// Battery: (V)
device.setCapabilityValue('measure_voltage', values[8]).catch(this.error);

// Wind lull: {values[4]} m/s
// Report interval: {values[9]} minutes
// Local Day Rain Accumulation: {values[11]} mm - always null with UDP API
// Precipitation type: {values[12]}
// Wind sample interval: {values[13]} seconds

this._isRaining = rain > 0;
this._updateRainFlow(rain);
}

rainStartEvent(message) {
console.log(`Sky rain start: ${JSON.stringify(message)}`);
// console.log(`Sky rain start: ${JSON.stringify(message)}`);

const device = this._getDevice(message.serial_number);
if (!device)
Expand All @@ -90,10 +85,10 @@ class SkyDriver extends Homey.Driver {

const timestamp = values[0];

this._isRaining = true;

let tokens = {}
let state = { 'serial_number': message.serialNumber }
let state = {}

this._isRaining = true;

this._rainStartTrigger.trigger(device, tokens, state)
.then()
Expand All @@ -116,7 +111,7 @@ class SkyDriver extends Homey.Driver {
const windDirection = values[2];

let tokens = {}
let state = { 'serial_number': message.serialNumber, 'wind_speed': windSpeed, 'last_triggered_wind_speed': this._lastRapidWindSpeed }
let state = { 'wind_speed': windSpeed }

this._windAboveTrigger.trigger(device, tokens, state)
.then()
Expand All @@ -126,34 +121,21 @@ class SkyDriver extends Homey.Driver {
.then()
.catch(this.error)

this._lastRapidWindSpeed = windSpeed;
this._lastWindSpeed = windSpeed;
}

_initFlows() {
this._rainStartTrigger = new Homey.FlowCardTriggerDevice('rain_start').register();
this._rainStartTrigger = new Homey.FlowCardTriggerDevice('rain_start')
.register();

this._windAboveTrigger = new Homey.FlowCardTriggerDevice('wind_above')
.registerRunListener((args, state) => {
// console.log(`Evaluate wind trigger condition ${state.last_triggered_wind_speed} <= ${args.wind_speed} && ${state.wind_speed} > ${args.wind_speed}...`);

// args parameter, this is the user input
// state parameter, as passed in trigger()

// console.log(args.sky);
// console.log(args.sky.data);

// TODO: Only resolve true for correct serial number.

// If true, this flow should run
return Promise.resolve(state.last_triggered_wind_speed <= args.wind_speed && state.wind_speed > args.wind_speed);
return Promise.resolve(state.wind_speed > args.wind_speed);
}).register();

this._windBelowTrigger = new Homey.FlowCardTriggerDevice('wind_below')
.registerRunListener((args, state) => {
// TODO: Only resolve true for correct serial number.

// If true, this flow should run
return Promise.resolve(state.last_triggered_wind_speed > args.wind_speed && state.wind_speed <= args.wind_speed);
return Promise.resolve(state.wind_speed <= args.wind_speed);
}).register();

this._rainCondition = new Homey.FlowCardCondition('is_raining')
Expand All @@ -165,12 +147,14 @@ class SkyDriver extends Homey.Driver {
this._windCondition = new Homey.FlowCardCondition('is_windy')
.register()
.registerRunListener((args, state) => {

// console.log(`Wind condition run: ${args}, ${state} for ${args.my_device}`);
return Promise.resolve(this._lastRapidWindSpeed > args.wind_speed);
return Promise.resolve(this._lastWindSpeed > args.wind_speed);
});
}

_updateRainFlow(rain) {
this._isRaining = rain > 0;
}

_getDevice(deviceSerialNumber) {
const device = this.getDevice({ "serialNumber": deviceSerialNumber });
if (device instanceof Error) {
Expand Down

0 comments on commit 5a8e7c7

Please sign in to comment.