sebr / bhyve-home-assistant

Orbit BHyve custom component for Home Assistant
MIT License
252 stars 42 forks source link

Switch appears to be on all the time and cannot be switched off #96

Closed dmshimself closed 2 years ago

dmshimself commented 2 years ago

Describe the bug After the most recent BHYVE upgrade I still have a switch in HA but in the UI it now is always on. If I toggle the switch to off, it moves back to on again after a few moments. On the BHYVE timer, the switch is actually off all the time. I have included the log further down this report and at the end I tried to turn the switch off and on, but nothing seems to be shown in the log.

Expected behaviour The switch in the UI should represent the status of the switch

BHyve devices I have a BHYVE gateway and a single tap timer

Logs

2021-12-18 18:31:58 DEBUG (MainThread) [custom_components.irrigation_unlimited] START
2021-12-18 18:31:59 DEBUG (MainThread) [custom_components.bhyve.pybhyve.client] Logged in
2021-12-18 18:31:59 DEBUG (MainThread) [custom_components.irrigation_unlimited] REGISTER [2021-12-18 18:31:00] controller: 1, zone: 0, entity: binary_sensor.irrigation_unlimited_c1_m
2021-12-18 18:31:59 DEBUG (MainThread) [custom_components.irrigation_unlimited] CALL [2021-12-18 18:31:00] service: enable, controller: 1, zone: 0, data: null
2021-12-18 18:32:00 DEBUG (MainThread) [custom_components.bhyve] Devices: [{"last_connected_at": "2021-12-15T16:04:12.581Z", "address": "REDACTED", "timezone": {"dst_offset": 3600, "raw_offset": 43200, "timezone_id": "Pacific/Auckland", "timezone_name": "New Zealand Daylight Time"}, "full_location": "REDACTED", "firmware_version": "0030", "name": "B-hyve1", "type": "bridge", "updated_at": "2021-12-15T16:04:12.581Z", "reference": "446755212ddf", "mac_address": "446755212ddf", "mesh_id": "5fffdce14f0cd37b7964ff3e", "status": {"next_start_programs": [], "next_start_time": "1970-01-01T00:00:00+13:00", "watering_status": null}, "wifi_version": 0, "id": "5fffdce14f0cd37b7964ff3c", "num_stations": 0, "user_id": "5fffd1d64f0c33b47f58fa39", "device_gateway_topic": "devices-7", "hardware_version": "BH1-0001", "is_connected": true, "location": "REDACTED", "created_at": "2021-01-14T05:55:45.400Z"}, {"last_connected_at": "2021-12-16T20:01:58.821Z", "address": "REDACTED", "water_sense_mode": "off", "scheduled_modes": {"auto": {"at": "", "annually": false}, "off": {"at": "", "annually": false}}, "timezone": {"dst_offset": 3600, "raw_offset": 43200, "timezone_id": "Pacific/Auckland", "timezone_name": "New Zealand Daylight Time"}, "full_location": "REDACTED", "weather_forecast_location_id": "5e2bfaea4f0c0b73fd19e1bd", "firmware_version": "0041", "name": "Smart Hose Timer 1", "type": "sprinkler_timer", "manual_preset_runtime_sec": 120, "battery": {"percent": 43, "charging": false}, "restricted_frequency": null, "weather_delay_thresholds": {"precip_prob": 30, "precip_in": 0.125, "wind_speed_mph": 20, "freeze_temp_f": 37}, "updated_at": "2021-12-18T04:32:00.972Z", "reference": "446755212ddf-53470", "mac_address": "446755126458", "weather_station_id": null, "mesh_id": "5fffdce14f0cd37b7964ff3e", "status": {"run_mode": "manual", "next_start_programs": ["b"], "rain_sensors": [], "rain_delay_overridden_at": "2021-10-24T01:01:19.252Z", "watering_status": {"program": null, "current_station": 1, "started_watering_station_at": "2021-12-16T19:00:34.000Z", "stations": [{"run_time": 2.0, "station": 1}], "rain_sensor_hold": false}, "rain_delay_suggested_at": "2021-12-12T19:01:04.235Z", "rain_delay": 0, "flow_sensor": null, "next_start_time": "2021-10-24T14:00:00+13:00", "rain_delay_started_at": "2021-12-16T18:01:29.000Z"}, "id": "5fffde5f4f0c33b47f58fa9a", "num_stations": 1, "notes": "", "zones": [{"station": 1, "slope_grade": 0, "sun_shade": "mostly_sunny", "name": "Veggies", "landscape_type": "warm_season_turf", "num_sprinklers": 1, "soil_type": "loam", "catch_cup_volumes": [], "catch_cup_run_time": 0, "smart_watering_enabled": false, "sprinkler_type": "drip"}], "user_id": "5fffd1d64f0c33b47f58fa39", "google_home_status": null, "device_gateway_topic": "devices-7", "hardware_version": "HT25-0000", "is_connected": true, "location": "REDACTED", "created_at": "2021-01-14T06:02:07.314Z", "suggested_start_time": "06:00", "et_id": "5644ff77ad27a7777fff765e"}]
2021-12-18 18:32:00 DEBUG (MainThread) [custom_components.bhyve] Programs: [{"pending_timer_ack": true, "name": "Veggies", "program_start_date": "2021-08-06T01:11:12.016Z", "frequency": {"type": "days", "days": [0, 1, 2, 3, 4, 5, 6]}, "program_end_date": null, "is_basic_program": false, "group_id": "609cadeb4f0cc23b2fbd22bc", "updated_at": "2021-08-06T01:11:33.032Z", "updated_via": "wifi", "start_times": ["06:00", "18:00"], "id": "5fffed124f0cd37b7964ffdb", "budget": 100, "group_run_times": [], "device_id": "5fffde5f4f0c33b47f58fa9a", "program": "a", "run_times": [{"run_time": 15, "station": 1}], "enabled": false, "created_at": "2021-01-14T07:04:50.016Z"}, {"pending_timer_ack": true, "name": "Watering Can", "program_start_date": "2021-10-24T00:32:55.927Z", "frequency": {"type": "days", "days": [0, 1, 2, 3, 4, 5, 6]}, "program_end_date": null, "is_basic_program": false, "group_id": "6174a9bf4f0cf51668ed527c", "updated_at": "2021-10-24T00:33:03.923Z", "updated_via": "wifi", "start_times": ["14:00"], "id": "609cae994f0cc5e78a2d29ce", "budget": 170, "group_run_times": [], "device_id": "5fffde5f4f0c33b47f58fa9a", "program": "b", "run_times": [{"run_time": 30, "station": 1}], "enabled": false, "created_at": "2021-05-13T04:44:09.597Z"}]
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Creating switch: Smart Hose Timer 1 rain delay
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Creating switch: Veggies zone
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Veggies zone watering_status: {'program': None, 'current_station': 1, 'started_watering_station_at': '2021-12-16T19:00:34.000Z', 'stations': [{'run_time': 2.0, 'station': 1}], 'rain_sensor_hold': False}
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Veggies Zone: Watering program Veggies (a) is not enabled, skipping
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Veggies Zone: Watering program Watering Can (b) is not enabled, skipping
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Creating switch: Program Veggies
2021-12-18 18:32:00 INFO (MainThread) [custom_components.bhyve.switch] Creating switch: Program Watering Can
2021-12-18 18:32:01 INFO (MainThread) [custom_components.bhyve.pybhyve.websocket] Authenticating websocket
2021-12-18 18:32:01 INFO (MainThread) [custom_components.bhyve.pybhyve.websocket] Websocket connected
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating state sensor: Smart Hose Timer 1 state
2021-12-18 18:32:25 DEBUG (MainThread) [custom_components.bhyve.sensor] State sensor Smart Hose Timer 1 state setup: State: manual | Available: True
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating history sensor: Veggies zone history
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating battery sensor: Smart Hose Timer 1 battery level
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating state sensor: Smart Hose Timer 1 state
2021-12-18 18:32:25 DEBUG (MainThread) [custom_components.bhyve.sensor] State sensor Smart Hose Timer 1 state setup: State: manual | Available: True
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating history sensor: Veggies zone history
2021-12-18 18:32:25 INFO (MainThread) [custom_components.bhyve.sensor] Creating battery sensor: Smart Hose Timer 1 battery level
2021-12-18 18:32:27 ERROR (MainThread) [homeassistant.components.sensor] Platform bhyve does not generate unique IDs. ID 446755126458:5fffde5f4f0c33b47f58fa9a:state already exists - ignoring sensor.smart_hose_timer_1_state
2021-12-18 18:32:27 ERROR (MainThread) [homeassistant.components.sensor] Platform bhyve does not generate unique IDs. ID 446755126458:5fffde5f4f0c33b47f58fa9a:battery already exists - ignoring sensor.smart_hose_timer_1_battery_level
2021-12-18 18:32:29 ERROR (MainThread) [homeassistant.components.sensor] Platform bhyve does not generate unique IDs. ID 446755126458:5fffde5f4f0c33b47f58fa9a:1:history already exists - ignoring sensor.veggies_zone_history
dmshimself commented 2 years ago

image

Paimon2 commented 2 years ago

Also having this issue, any fix?

tux43 commented 2 years ago

I think I’m having the issue too. If I reboot Home Assistant it reverts back. However every time I water HA keeps displaying it on.

sebr commented 2 years ago

@dmshimself sorry about the delay getting back to this. Are you still seeing this issue? The logs you added show that there are duplicated entities which were created, is it possible there was a stray old configuration?

@Paimon2 / @tux43 can you please send me the debugging logs (including the websocket event dumps) by adding this to your config and then restarting HA:

logger:
  logs:
    custom_components.bhyve: debug # logs for bhyve custom_component
    pybhyve: debug                 # logs for pybhyve (websocket event dump)

Once you've done this, please toggle the watering on/off and wait for it to finish then dump the results here.

Thanks!

dmshimself commented 2 years ago

In the past I uninstalled/reinstaled the HACS BHYVE integration to try and fix up the issue with not being able to flick the switch. Currently there is only one entity for the switch in HA and the delete button in HA isn't enabled, so I'm not able to remove the installed switch that way. I have a develpment environment too, so I'm happy to uninstall/reinstall again or anything else really. I've currently had to use the BHYVE app to set up a schedule which isn't perfect, but keeps things running ok and HA 'sees' the switch going off and on when this external schedule kicks in.

sebr commented 2 years ago

@dmshimself ah yes this is a bit annoying - in order to remove the existing entities you need to uninstall the integration, restart HA, remove entities, then reinstall the integration and restart again.... super painful. Unfortunately very low on time to look into implementing some newer HA features that would improve this situation.

dmshimself commented 2 years ago

Hi @sebr - and thanks for the thoughts. I've been through that sequence and double checked there were no entities being filtered out after removing the integration and there were not. I had to comment out sections in configuration.yaml before I could restart, but that's fine. I then reinstalled, restarted, uncommented the BHYVE items, cleared the log and restarted again. But the errors in the log persists. Is there another way to remove this errant entity?

sensor.hose_timer_battery_level: parsing error, expected number and received None 1:56:35 PM – (ERROR) statistics Platform bhyve does not generate unique IDs. ID 446755126458:5fffde5f4f0c33b47f58fa9a:state already exists - ignoring sensor.smart_hose_timer_1_state 1:56:31 PM – (ERROR) Sensor - message first occurred at 1:56:28 PM and shows up 3 times

dmshimself commented 2 years ago

More from me - when I look at the entities using the developer tab (danger will robinson), I see the device ID for all the BHYVE entities is the same - the 5fffde5f4f0c33b47f58fa9a given above. Could this be the root of the problem?

sebr commented 2 years ago

Very odd, is there any chance you have multiple copies of the integration configured in configuration.yaml (or even just the sensor platform)? Do a search for platform: bhyve across your configuration file/s.

More from me - when I look at the entities using the developer tab (danger will robinson), I see the device ID for all the BHYVE entities is the same - the 5fffde5f4f0c33b47f58fa9a given above. Could this be the root of the problem?

If you are referring to seeing this in the entity attributes, then no this is not a concern. This is the bhyve device id (not related to home assistant).

dmshimself commented 2 years ago

Doh, Doh Doh!!! Yep I must have done a copy paste in the past. All sorted out - many thanks for the assist.

tux43 commented 2 years ago

I've uninstalled and reinstalled with the same issue happening. I've uploaded the logs as requested custom_components.bhyve.log.gz .

sebr commented 2 years ago

Thanks everyone, I've reproduced this and will take a look at fixing.

sebr commented 2 years ago

Okay, coming back to this and I can't reproduce anymore :'(. It might be a specific combination of BHyve events which I'm not capturing, related to a specific configuration set. I'll continue to investigate, but if anybody can shed any light that would be very helpful.

Thanks!

allistermaguire commented 2 years ago

I've uninstalled and reinstalled with the same issue happening. I've uploaded the logs as requested custom_components.bhyve.log.gz .

@tux43 What device do you have? your issue seems slightly different to the original for this ticket, but similar to an issue #106

mcvicthor commented 2 years ago

I have the same issue on Orbit B-Hyve. What I noticed is that most of the times it will switch off eventually. The program ran for 15 minutes but switched OFF one hour later. Manually switching to OFF would flip back to ON by itself.

image

tux43 commented 2 years ago

I've uninstalled and reinstalled with the same issue happening. I've uploaded the logs as requested custom_components.bhyve.log.gz .

@tux43 What device do you have? your issue seems slightly different to the original for this ticket, but similar to an issue #106

I have a Smart Watering Hose Timer - https://www.orbitonline.com/collections/b-hyve/products/b-hyve-smart-hose-watering-timer

Here are some screen grabs from the app showing firmware etc..

jonathantidwell commented 2 years ago

For those impacted by this issue, it seems a homeassistant.update_entity service call will yield a correct result. From my toying around with this, it seems like the switch will still send the command to turn off, it just won't update the status. I'm currently experimenting with an automation to fix until @sebr conjures up a fix. Of course, modify to your liking:

- id: "update_my_spigot"
  alias: "Update My Spigot"
  trigger:
  - entity_id: switch.my_spigot
    platform: state
    to: "on"
  - platform: event
    event_type: automation_reloaded
  condition:
  - condition: state
    entity_id: switch.my_spigot
    state: "on"
  action:
  - repeat:
      while:
      - condition: state
        entity_id: switch.my_spigot
        state: "on"
      sequence:
      - service: homeassistant.update_entity
        target:
          entity_id: switch.my_spigot
      - delay: "00:00:10"
  mode: single
dmshimself commented 2 years ago

neat - many thanks for sharing that

tux43 commented 2 years ago

For those impacted by this issue, it seems a homeassistant.update_entity service call will yield a correct result. From my toying around with this, it seems like the switch will still send the command to turn off, it just won't update the status. I'm currently experimenting with an automation to fix until @sebr conjures up a fix. Of course, modify to your liking:

Oh - that is great!! Many thanks @jonathantidwell

sebr commented 2 years ago

Hi folks, I've made a small tweak to turn off the switch when receiving the event change_mode: auto|off. Hopefully this fixes the issue - but I'll need your help to verify and keep a lookout for any other issues as I've not been able to reproduce.

This change is available in version 2.2.0-beta0 which you should be able to install via HACS if you enable beta versions (nb you might need to select "redownload" to view this beta version).

Please let me know if this improves the situation?

allistermaguire commented 2 years ago

Hey @sebr, there is a bug in the code, it should to be:

        if event in (EVENT_DEVICE_IDLE, EVENT_WATERING_COMPLETE) or (
            event == EVENT_CHANGE_MODE and data.get("mode") in ("off", "auto")
        ):

but I can confirm that it will resolve the issue.

FYI, for multi zone systems you only get the EVENT_CHANGE_MODE at the end. Ie: if the program (Smart or Manual) includes multiple zones, the zone switches will only be updated once the last zone has finished watering.

sebr commented 2 years ago

Yup thanks so much... Released 2.2.2-beta1.

You're correct re the multi-zone systems. This is a long standing bug as reported at #41

Are you happy to contribute logs or thoughts on how to fix on that issue? I don't have the right device to reverse engineer it :)

m-theredhead commented 2 years ago

I upgraded to the 2.2.2-beta1 yesterday. This morning after my 4 zones ran, they all still show as being active even though they are not.

sebr commented 2 years ago

I upgraded to the 2.2.2-beta1 yesterday. This morning after my 4 zones ran, they all still show as being active even though they are not.

@m-theredhead which device(s) are you using?

m-theredhead commented 2 years ago

@m-theredhead which device(s) are you using?

It is the B-Hyve 6 zone sprinkler controller. It worked fine until recently ( could have been weeks or months ). Upon restarting home assistant, the zones all show off, but once the zone runs, it reports as being on in home-assistant indefinitely.

sebr commented 2 years ago

@m-theredhead which device(s) are you using?

It is the B-Hyve 6 zone sprinkler controller. It worked fine until recently ( could have been weeks or months ). Upon restarting home assistant, the zones all show off, but once the zone runs, it reports as being on in home-assistant indefinitely.

Okay, do you run the zones in sequence as part of one program or are they separate? Could you be running into #41 ?

m-theredhead commented 2 years ago

Okay, do you run the zones in sequence as part of one program or are they separate?

I have 4 zones and 3 programs. Most programs only contains 1 zone and 1 program contains 2 zones. They all run in the early mornings and seem to come on at the right time, but none of them ever turn off. It doesn't seem to match the description in #41 as they don't turn off when the program ends either.

allistermaguire commented 2 years ago

Hey @sebr I have captured some more data and the change_mode event isn't generally sent after a watering program as I guess the mode isn't actually changing. I tested with manually watering initially, and that is instant, but that is changing from manual to auto.

rsampayo commented 2 years ago

I had the same problem. Removed integration, deleted entities and installed beta version. It's now working.

rsampayo commented 2 years ago

Follow up. Now the problem is that once the program runs and the zone is turned on it stays on (on Home assistant). I have to manually turn it off on HA. If I turn one zone off all of them turn off.

m-theredhead commented 2 years ago

This issue seems to have gone away for me in the last week or so. Not sure if some of the recent HA updates fixed it or what. Anyone else now no longer seeing the issue?

allistermaguire commented 2 years ago

It looks like Obit B-Hyve has fixed/reimplemented the watering_complete event for the irrigation controllers. Probably related to the new Obit B-Hyve app released last week.

2022-04-04` 07:05:02 DEBUG (MainThread) [custom_components.bhyve.pybhyve.websocket] msg received WSMessage(type=<WSMsgType.TEXT: 1>, data='{"timestamp":"2022-04-03T19:05:01.000Z","event":"watering_complete","stream-id":"XXXXX-XXXX-XXX-XXX-XXXXXXX","client-topics":["device-clients-2","device-clients-1"],"gateway-topic":"devices-2","device_id":"XXXXXXXXXXXXX"}', extra='')
sebr commented 2 years ago

I haven't seen this issue in a long time, hoping it has resolved itself. Please reopen if it appears again!