haywirecoder / homebridge-flobymoen

Homebridge Module for Flo by Moen Smart Water System
MIT License
14 stars 2 forks source link

node.js 16.13 #7

Closed Sujovian closed 2 years ago

Sujovian commented 2 years ago

Describe The Bug: Upon upgrading to Homebridge 1.4, multiple plugins requested 14.18 or higher. Following Homebridge's recommended upgrade procedure, I'm now running 16.13.2. The flo plugin is now in a loop, and won't fully launch.

To Reproduce: upgrade Node.js to 16.13.2

Expected behavior: flo by men launches as expected. All other plugins I have are unaffected by the new version of node.js Logs:

[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Restarting Process...
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Launched child bridge with PID 11826
[1/21/2022, 6:00:47 PM] The plugin "homebridge-flobymoen" requires Node.js version of ^14.17.5 which does not satisfy the current Node.js version of v16.13.2. You may need to upgrade your installation of Node.js - see https://git.io/JTKEF
[1/21/2022, 6:00:47 PM] Registering platform 'homebridge-flobymoen.Flo-by-Moen'
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Loaded homebridge-flobymoen v1.0.3 child bridge successfully
[1/21/2022, 6:00:47 PM] Loaded 4 cached accessories from cachedAccessories.0EA11D172112.
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Starting communication with Flo portal
[1/21/2022, 6:00:47 PM] Homebridge v1.4.0 (HAP v0.10.0) (Flo-by-Moen) is running on port 48180.
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Using local cache Flo token.
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Token will refresh in 3 hour(s) and 4 min(s).
[1/21/2022, 6:00:47 PM] [Flo-by-Moen] Initiaizing Flo devices...
[1/21/2022, 6:00:49 PM] [Flo-by-Moen] Flo device updates complete, background polling process started.
Device will be polled each 2 min(s) 0 second(s).
TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at new NodeError (node:internal/errors:371:5)
    at Hash.update (node:internal/crypto/hash:105:11)
    at Object.generate (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/uuid.ts:11:11)
    at new FloSmartWater (/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:23:25)
    at FloByMoenPlatform.refreshAccessories (/usr/local/lib/node_modules/homebridge-flobymoen/index.js:98:37)
    at /usr/local/lib/node_modules/homebridge-flobymoen/index.js:77:18
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[1/21/2022, 6:00:49 PM] [Flo-by-Moen] Child bridge process ended
[1/21/2022, 6:00:49 PM] [Flo-by-Moen] Process Ended. Code: 1, Signal: null
[1/21/2022, 6:00:56 PM] [Flo-by-Moen] Restarting Process...
            "name": "Flo-by-Moen",
            "auth": {
                "username": "xxx",
                "password": "xxx"
            },
            "disableCache": false,
            "showTemperatureAndHumidity": true,
            "enableValveControl": true,
            "showHealthTestSwitch": false,
            "deviceRefresh": 120,
            "sleepRevertMinutes": 120,
            "_bridge": {
                "username": "MAC,
                "port": 48180
            },
            "platform": "Flo-by-Moen"

Screenshots:

Environment:

haywirecoder commented 2 years ago

Hi,

I am not able reproduce your issue on either one of Homebridge instance running the latest versions. The only difference I notice is your are running Homebridge on MacOS. However, it seems the issue is a "type" issue when generating the unique GUID. I have made some changes to assure the correct type, but since I can't reproduce the error I don't know if the problem is corrected. You can test/validate using following steps:

  1. Replace follow files in /usr/local/lib/node_modules/homebridge-flobymoen flomain.js index.js with the files in the repo

  2. Replace follow files in /usr/local/lib/node_modules/homebridge-flobymoen/accessories smartWater.js waterSensor.js with the files in the repo

  3. Restart and you should running the patch.

Sujovian commented 2 years ago

done. I disabled the plugin, uninstalled it, restarted, reinstalled it, patched it as requested above, re-entered login info, restarted homebridge, enabled the plugin, and now the logs say this:

[1/25/2022, 10:25:04 AM] [Flo-by-Moen] Launched child bridge with PID 56274 [1/25/2022, 10:25:04 AM] The plugin "homebridge-flobymoen" requires Node.js version of ^14.17.5 which does not satisfy the current Node.js version of v16.13.2. You may need to upgrade your installation of Node.js - see https://git.io/JTKEF [1/25/2022, 10:25:04 AM] Registering platform 'homebridge-flobymoen.Flo-by-Moen' [1/25/2022, 10:25:04 AM] [Flo-by-Moen] Loaded homebridge-flobymoen v1.0.3 child bridge successfully [1/25/2022, 10:25:04 AM] Loaded 0 cached accessories from cachedAccessories.0ECAEABE3C82. [1/25/2022, 10:25:04 AM] [Flo-by-Moen] Starting communication with Flo portal [1/25/2022, 10:25:04 AM] Homebridge v1.4.0 (HAP v0.10.0) (Flo-by-Moen) is running on port 38242. [1/25/2022, 10:25:04 AM] [Flo-by-Moen] Flo Info: Using local cache Flo token. [1/25/2022, 10:25:04 AM] [Flo-by-Moen] Flo Info: Token will refresh in 11 hour(s) and 53 min(s). [1/25/2022, 10:25:04 AM] [Flo-by-Moen] Initiaizing Flo devices... [1/25/2022, 10:25:06 AM] [Flo-by-Moen] Flo device updates complete, background polling process started. Device will be polled each 1 min(s) 30 second(s).

/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:13 this.id = device.serialNumber.toString(); ^ TypeError: Cannot read properties of undefined (reading 'toString') at new FloSmartWater (/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:13:35) at FloByMoenPlatform.refreshAccessories (/usr/local/lib/node_modules/homebridge-flobymoen/index.js:97:37) at /usr/local/lib/node_modules/homebridge-flobymoen/index.js:75:18 at processTicksAndRejections (node:internal/process/task_queues:96:5) [1/25/2022, 10:25:06 AM] [Flo-by-Moen] Child bridge process ended [1/25/2022, 10:25:06 AM] [Flo-by-Moen] Process Ended. Code: 1, Signal: null [1/25/2022, 10:25:13 AM] [Flo-by-Moen] Restarting Process...

haywirecoder commented 2 years ago

Hi,

Few questions about your setup.

  1. What is your configuration (e.g.1- Flo device, 2- Water sensor?)
  2. I notice in your original post you have this setting in Flo platform "_bridge": { "username": "MAC, "port": 48180 },

Are you running sub-bridge?

  1. Are you able to successful login into Flo portal with the provide username and password in flow portal?
Sujovian commented 2 years ago

I am running one shutoff valve and three water sensors. Yes I configured the plugin to run in a child bridge. Yes my username & password work when I login to the web portal at meetflo.com

Another variable for you that "might" be relevant: Last week I had the Shutoff Valve replaced under warranty. I installed the new unit on Thursday. I had to remove the old device from my account and add the new one to replace it. The following day is when I did the Hb upgrade from 1.3.9 to 1.4.0 and the node.js upgrade from 14.17 to 16.13, after which the plugin broke.

haywirecoder commented 2 years ago

Ah, the replacement maybe the root of the problem. The error is indicating the serial number is not defined (aka missing), thus the plug-in is not able to generate unique ID for Homekit. I have updated the code to now use the Device ID that the Flo system creates rather than the device serial number. Basing the generate on Device ID is better overall, since without the device ID the API for refreshing the device wouldn't work -- so it is required field. In theory this should fix the problem -- you can repeat the same process to test, by replace the files. I am running this version now in my environment to make sure it didn't break anything else, so far no issues.

However, a fundemental question does a raise as to why the serial number is missing when calling the APIs. If you have time, you can put the plug-in in debug and find "Device Raw Data: " entry in dump/log. The log entry is the raw version of data from the APIs. Do you see the serial number?, or when they replace it did create a new field. Since Flo doesn't document this API it hard to know how they are managing this data set.

Sujovian commented 2 years ago

In the Flo app, under Serial#, it says "not available". On the meetflo.com portal, SN#s aren't shown at all, only the DeviceID. It does appear DeviceID is the field it wants to use to reference the device.

Regardless, here's the debug log dump:

[1/26/2022, 10:19:08 AM] [Flo-by-Moen] Initiaizing Flo devices... [1/26/2022, 10:19:09 AM] [Flo-by-Moen] Device Raw Data: { isConnected: true, fwVersion: '7.0.15', lastHeardFromTime: '2022-01-26T15:09:00Z', fwProperties: { alarm_away_high_flow_rate_shut_off_enabled: true, alarm_away_high_water_use_shut_off_enabled: true, alarm_away_long_flow_event_shut_off_enabled: true, alarm_away_v2_shut_off_enabled: true, alarm_home_high_flow_rate_shut_off_deferment: 300, alarm_home_high_flow_rate_shut_off_enabled: true, alarm_home_high_water_use_shut_off_deferment: 300, alarm_home_high_water_use_shut_off_enabled: true, alarm_home_long_flow_event_shut_off_deferment: 300, alarm_home_long_flow_event_shut_off_enabled: true, alarm_shut_off_enabled: true, alarm_shutoff_id: '', alarm_shutoff_time_epoch_sec: -1, alarm_snooze_enabled: true, alarm_suppress_duplicate_duration: 300, alarm_suppress_until_event_end: false, data_flosense_first_launch_utc: '2022-01-21 22:01:08.497692', data_flosense_flodetect_hash: '731b59071d3ac1f64427e2a04b2d2e6f', data_flosense_force_retrain: 0, data_flosense_is_generic_model: 1, data_flosense_min_flodetect_sec: 0, data_flosense_min_irr_sec: 180, data_flosense_model_hash: '81f1279ffcc98034215cb207dcfc4158', data_flosense_pad_min: 2, data_flosense_retrain_op: 5, data_flosense_status_interval: 1200, data_flosense_suppress_reboot: 0, data_flosense_verbosity: 1, device_data_free_mb: 1775, device_data_mb: 1951, device_installed: true, device_mem_available_kb: 276692, device_rootfs_free_kb: 723244, device_timestamp: 1642802712, device_uptime_sec: 32212672, feature_mode: 'default', flodetect_post_enabled: true, flodetect_post_frequency: 0, flodetect_storage_days: 60, flosense_action: '', flosense_deployment_result: 'success', flosense_link: '', flosense_shut_off_enabled: true, flosense_shut_off_level: 2, flosense_state: 'active', flosense_version_app: '3.0.2', flosense_version_model: '3.0.0', fw_ver: '7.0.15', fw_ver_a: '7.0.15', fw_ver_b: '', heartbeat_frequency: 1800, ht_attempt_interval: 60000, ht_check_window_max_pressure_decay_limit: 0.1, ht_check_window_width: 30000, ht_ignore_flow_checking: false, ht_max_open_closed_pressure_decay_pct_limit: 2, ht_max_pressure_growth_limit: 3, ht_max_pressure_growth_pct_limit: 3, ht_max_valve_closures_per_24h: 3, ht_min_computable_point_limit: 3, ht_min_pressure_limit: 10, ht_min_r_squared_limit: 0.9, ht_min_slope_limit: -0.6, ht_phase_1_max_pressure_decay_limit: 6, ht_phase_1_max_pressure_decay_pct_limit: 10, ht_phase_1_time_index: 12000, ht_phase_2_max_pressure_decay_limit: 6, ht_phase_2_max_pressure_decay_pct_limit: 10, ht_phase_2_time_index: 30000, ht_phase_3_max_pressure_decay_limit: 3, ht_phase_3_max_pressure_decay_pct_limit: 5, ht_phase_3_time_index: 240000, ht_phase_4_max_pressure_decay_limit: 1.5, ht_phase_4_max_pressure_decay_pct_limit: 5, ht_phase_4_time_index: 480000, ht_pre_delay: 0, ht_recent_flow_event_cool_down: 1000, ht_retry_on_fail_interval: 900000, ht_scheduler_end: '00:00', ht_scheduler_start: '00:00', ht_scheduler_ultima_allotted_time_1: '10:00', ht_scheduler_ultima_allotted_time_2: '18:00', ht_scheduler_ultima_allotted_time_3: '02:00', ht_times_per_day: 1, log_bytes_sent: 99025, log_enabled: true, log_frequency: 3600, log_send: false, mender_check: false, mender_host: 'https://mender.flotech.co', mender_parts_link: '', mender_ping_delay: 300, mender_signature: '', motor_delay_close: 175, motor_delay_open: 0, motor_retry_count: 2, motor_timeout: 5000, mqtt_host: 'mqtt.flosecurecloud.com', mqtt_port: 8884, pes_away_max_duration: 3600, pes_away_max_pressure: 150, pes_away_max_temperature: 226, pes_away_max_volume: 50, pes_away_min_pressure: 20, pes_away_min_pressure_duration: 5, pes_away_min_temperature: 36, pes_away_min_temperature_duration: 10, pes_away_v1_high_flow_rate: 8, pes_away_v1_high_flow_rate_duration: 5, pes_away_v2_high_flow_rate: 0.5, pes_away_v2_high_flow_rate_duration: 5, pes_home_high_flow_rate: 1000, pes_home_high_flow_rate_duration: 20, pes_home_max_duration: 11294, pes_home_max_pressure: 150, pes_home_max_temperature: 226, pes_home_max_volume: 191, pes_home_min_pressure: 20, pes_home_min_pressure_duration: 5, pes_home_min_pressure_resolve: 25, pes_home_min_pressure_resolve_duration: 5, pes_home_min_temperature: 36, pes_home_min_temperature_duration: 10, pes_home_min_temperature_resolve: 40, pes_home_min_temperature_resolve_duration: 10, pes_moderately_high_pressure: 80, pes_moderately_high_pressure_count: 43200, pes_moderately_high_pressure_delay: 300, pes_moderately_high_pressure_period: 10, player_action: 'disabled', player_flow: 0, player_min_pressure: 40, player_pressure: 60, player_temperature: 50, power_downtime_last_24h: 0, power_downtime_last_7days: 0, power_downtime_last_reboot: 0, pt_state: 'ok', reboot_count: 5, reboot_count_7days: 0, reboot_reason: 'power_cycle', s3_bucket_host: 'api-bulk.meetflo.com', serial_number: '', system_mode: 5, tag: '', telemetry_batched_enabled: true, telemetry_batched_hf_enabled: true, telemetry_batched_hf_interval: 10800, telemetry_batched_hf_poll_rate: 100, telemetry_batched_interval: 300, telemetry_batched_pending_storage: 30, telemetry_batched_sent_storage: 30, telemetry_flow_rate: 0, telemetry_pressure: 76.7, telemetry_realtime_change_gpm: 0, telemetry_realtime_change_psi: 0, telemetry_realtime_enabled: true, telemetry_realtime_interval: 1, telemetry_realtime_packet_uptime: 1088, telemetry_realtime_session_last_epoch: 1642802021543, telemetry_realtime_sessions_7days: 1, telemetry_realtime_timeout: 299, telemetry_temperature: 76, valve_actuation_count: 10, valve_actuation_timeout_count: 0, valve_state: 1, vpn_enabled: false, vpn_ip: '', water_event_enabled: true, water_event_min_duration: 2, water_event_min_gallons: 0.1, wifi_bytes_received: 430965, wifi_bytes_sent: 11040167, wifi_disconnections: 2, wifi_rssi: -53, wifi_sta_country: 'us', wifi_sta_enc: 'psk2', wifi_sta_ip: '192.168.1.123', wifi_sta_ssid: 'XXXX', zit_auto_count: 0, zit_manual_count: 0 }, id: 'XXXXXXXXXXXX', macAddress: 'XXXXXXXX', nickname: 'Flo Shutoff', isPaired: true, deviceModel: 'flo_device_075_v2', deviceType: 'flo_device_v2', irrigationType: 'not_plumbed', prvInstallation: 'before', purchaseLocation: 'meetflo', systemMode: { isLocked: true, shouldInherit: true, lastKnown: 'sleep', target: 'sleep' }, valve: { lastKnown: 'open' }, installStatus: { isInstalled: true, installDate: '2022-01-21T21:48:33.609Z' }, learning: { enabled: true }, notifications: { pending: { infoCount: 0, warningCount: 0, criticalCount: 0, alarmCount: [], info: [Object], warning: [Object], critical: [Object] } }, hardwareThresholds: { gpm: { okMin: 0, okMax: 29, minValue: 0, maxValue: 35 }, psi: { okMin: 30, okMax: 80, minValue: 0, maxValue: 100 }, lpm: { okMin: 0, okMax: 110, minValue: 0, maxValue: 130 }, kPa: { okMin: 210, okMax: 550, minValue: 0, maxValue: 700 }, tempF: { okMin: 50, okMax: 80, minValue: 0, maxValue: 100 }, tempC: { okMin: 10, okMax: 30, minValue: 0, maxValue: 40 } }, connectivity: { rssi: -52, ssid: 'ChaBlaM' }, telemetry: { current: { gpm: 0, psi: 76.5, tempF: 86, updated: '2022-01-25T20:56:58Z' } }, healthTest: { config: { enabled: true, timesPerDay: 1, start: '19:00', end: '19:00' } }, shutoff: { scheduledAt: '1970-01-01T00:00:00.000Z' }, actionRules: [], location: { id: 'XXXXXX' }

haywirecoder commented 2 years ago

Thanks,

Good to know that the SN# can be missing, the new code that is posted in the repo should correct the issue since I have remove the dependence on SN#. It also default to an empty string, if unsuccessful at obtainning from the APIs. I have a few other minor tweaks to complete and will official push out a release soon. BTW... I have XXXX out all your device IDs, MAC address and other data. Don't believe they can be used for malicious purposes without authentication data, but just in case.

Sujovian commented 2 years ago

The plugin is now working from a functionality standpoint. That said, I am now getting a recurring message in the Homebridge logs:

[1/27/2022, 10:45:15 AM] [homebridge-flobymoen] This plugin generated a warning from the characteristic 'In Use': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info. [1/27/2022, 10:45:15 AM] [homebridge-flobymoen] This plugin generated a warning from the characteristic 'In Use': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info.

It appears twice in the logs, roughly every five mins. Doesn't appear to affect functionality though.

Edit (1-27-2022): Here's the additional output of this repeating log entry under debug mode: [1/27/2022, 1:11:39 PM] [homebridge-flobymoen] This plugin generated a warning from the characteristic 'Active': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info. [1/27/2022, 1:11:39 PM] [homebridge-flobymoen] Error: at Active.Characteristic.characteristicWarning (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2142:105) at Active.Characteristic.validateUserInput (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2030:14) at Active.Characteristic.updateValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1457:20) at Valve.Service.updateCharacteristic (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:481:35) at FloSmartWater.refreshState (/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:81:18) at FlobyMoem.emit (node:events:390:28) at FlobyMoem.refreshDevice (/usr/local/lib/node_modules/homebridge-flobymoen/flomain.js:414:18) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at FlobyMoem.backgroundRefresh (/usr/local/lib/node_modules/homebridge-flobymoen/flomain.js:448:13) [1/27/2022, 1:11:39 PM] [homebridge-flobymoen] This plugin generated a warning from the characteristic 'In Use': characteristic value expected valid finite number and received "undefined" (undefined). See https://git.io/JtMGR for more info. [1/27/2022, 1:11:39 PM] [homebridge-flobymoen] Error: at InUse.Characteristic.characteristicWarning (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2142:105) at InUse.Characteristic.validateUserInput (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2030:14) at InUse.Characteristic.updateValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1457:20) at Valve.Service.updateCharacteristic (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:481:35) at FloSmartWater.refreshState (/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:82:18) at FlobyMoem.emit (node:events:390:28) at FlobyMoem.refreshDevice (/usr/local/lib/node_modules/homebridge-flobymoen/flomain.js:414:18) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at FlobyMoem.backgroundRefresh (/usr/local/lib/node_modules/homebridge-flobymoen/flomain.js:448:13)

Sujovian commented 2 years ago

Forgot to mention, I also get an error similar to above, related to the serial# field, but it only shows up after restarting HB or the child bridge. I enabled debug, and here's what the Serial error yields:

[1/27/2022, 11:31:40 AM] [homebridge-flobymoen] This plugin generated a warning from the characteristic 'Serial Number': [Serial Number] characteristic must have a length of more than 1 character otherwise HomeKit will reject this accessory, ignoring new value. See https://git.io/JtMGR for more info. [1/27/2022, 11:31:40 AM] [homebridge-flobymoen] Error: at SerialNumber.Characteristic.characteristicWarning (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2142:105) at SerialNumber.Characteristic.validateUserInput (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2094:14) at SerialNumber.Characteristic.setValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1376:20) at AccessoryInformation.Service.setCharacteristic (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:475:35) at FloSmartWater.setAccessory (/usr/local/lib/node_modules/homebridge-flobymoen/accessories/smartWater.js:95:10) at FloByMoenPlatform.refreshAccessories (/usr/local/lib/node_modules/homebridge-flobymoen/index.js:109:33) at /usr/local/lib/node_modules/homebridge-flobymoen/index.js:75:18 at processTicksAndRejections (node:internal/process/task_queues:96:5)

does not appear to affect functionality.
haywirecoder commented 2 years ago

Hi,

Looked at both issues. The first issue is straight forward due to the fact SN# is missing and I defaulted to an empty string but Homekit wants a longer string for SN. I updated the code to replaced the empty string with "NA" as default. The second issue is due to fact that that "targetstate" for the valve is missing (I am assuming due to fact it is a replacement and the value is just not yet populated until the valve is used a few times). Update the code to replace it with "lastknown" state of the valve which is always present. The corrected code is posted, if you want try the corrected version. Will post the new version after few days running in my setup.

Sujovian commented 2 years ago

Deployed latest code. both are confirmed resolved.

The plugin still complains about node.js version when the child bridge it is launched, but this doesn't appear to have any actual impact.

haywirecoder commented 2 years ago

Hi,

Great! Node version will be corrected as part of the release of the package.

haywirecoder commented 2 years ago

Hi, The official version 1.0.4 has been release with these fix.