home-assistant-ecosystem / home-assistant-cli

:computer: Command-line tool for Home Assistant
Other
437 stars 68 forks source link

Defined server is ignored when getting state history #332

Closed Azenet closed 2 years ago

Azenet commented 4 years ago

Hi,

I cannot figure out how to get state history when defining a server (either through env variables or --server), as it seems to be ignored when calling hass-cli --server https://x state history <entity> or env HASS_SERVER=https://x hass-cli state history <entity>. The CLI tries to find HASS on the network instead of using the configured server. I have tried with 0.9.0 and latest git (c0aa3a40abc8e16afc201cb07a3b1fa606b3088f).

Stack trace with breakpoint in _locate_ha() in config.py:

  venv/lib/python3.8/site-packages/homeassistant_cli/cli.py(40)run()
-> result = cli.main(standalone_mode=False)
  venv/lib/python3.8/site-packages/click/core.py(782)main()
-> rv = self.invoke(ctx)
  venv/lib/python3.8/site-packages/click/core.py(1259)invoke()
-> return _process_result(sub_ctx.command.invoke(sub_ctx))
  venv/lib/python3.8/site-packages/click/core.py(1259)invoke()
-> return _process_result(sub_ctx.command.invoke(sub_ctx))
  venv/lib/python3.8/site-packages/click/core.py(1066)invoke()
-> return ctx.invoke(self.callback, **ctx.params)
  venv/lib/python3.8/site-packages/click/core.py(610)invoke()
-> return callback(*args, **kwargs)
  venv/lib/python3.8/site-packages/click/decorators.py(73)new_func()
-> return ctx.invoke(f, obj, *args, **kwargs)
  venv/lib/python3.8/site-packages/click/core.py(610)invoke()
-> return callback(*args, **kwargs)
  venv/lib/python3.8/site-packages/homeassistant_cli/plugins/state.py(301)history()
-> data = api.get_history(ctx, list(entities), start_time, end_time)
  venv/lib/python3.8/site-packages/click/core.py(829)__call__()
-> return self.main(*args, **kwargs)
  venv/lib/python3.8/site-packages/click/core.py(782)main()
-> rv = self.invoke(ctx)
  venv/lib/python3.8/site-packages/click/core.py(1066)invoke()
-> return ctx.invoke(self.callback, **ctx.params)
  venv/lib/python3.8/site-packages/click/core.py(610)invoke()
-> return callback(*args, **kwargs)
  venv/lib/python3.8/site-packages/click/decorators.py(73)new_func()
-> return ctx.invoke(f, obj, *args, **kwargs)
  venv/lib/python3.8/site-packages/click/core.py(610)invoke()
-> return callback(*args, **kwargs)
  venv/lib/python3.8/site-packages/homeassistant_cli/plugins/state.py(73)list()
-> states = api.get_states(ctx)
  venv/lib/python3.8/site-packages/homeassistant_cli/remote.py(371)get_states()
-> req = restapi(ctx, METH_GET, hass.URL_API_STATES)
  venv/lib/python3.8/site-packages/homeassistant_cli/remote.py(74)restapi()
-> url = urllib.parse.urljoin(resolve_server(ctx) + path, "")
  venv/lib/python3.8/site-packages/homeassistant_cli/config.py(93)resolve_server()
-> ctx.resolved_server = _locate_ha()
> venv/lib/python3.8/site-packages/homeassistant_cli/config.py(37)_locate_ha()
-> _zeroconf = zeroconf.Zeroconf()

The _locate_ha() function isn't called when doing state get <entity>, for example.

Thank you!

kurumuru commented 4 years ago

I have same issue

mikenabhan commented 4 years ago

I am having this issue, documented a bit here because I didn't consider it was an upstream issue.

https://github.com/hassio-addons/addon-vscode/issues/100

johntdyer commented 4 years ago

yep, this was driving me nuts the lat two days...

~/Desktop ❯❯❯ hass-cli state history --since 6h binary_sensor.konnected_zone_2_front_and_rear_door                                                                                                                                                                                          ✘ 130
Trying to locate Home Assistant on local network...
Found and using https://automation.xxxxx.xxxxx.com as server
error: HomeAssistantCliError: Error while getting all states: 401: Unauthorized
Run with -x to see full exception information
~/Desktop ❯❯❯

next command works

~/Desktop ❯❯❯ hass-cli entity list kitchen                                                                                                                                                                                                                                                    ✘ 1
ENTITY_ID                                                  NAME                              DEVICE_ID                         PLATFORM    CONFIG_ENTRY_ID                   DISABLED_BY
switch.kitchen_bar_switch                                  Kitchen Bar Switch                8457c7f4356b4f83820d04acf14d6877  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
switch.kitchen_under_cabinet_right_side                    Kitchen Under Cabinet Side        857967db45534ea69fe7a3274721e378  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
light.kitchen_ceiling_dimmer                               Kitchen Ceiling                   b831a81397a54d7c91b928320454b930  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
zwave.kitchen_bar_switch                                   Kitchen Bar Switch                8457c7f4356b4f83820d04acf14d6877  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
zwave.kitchen_under_cabinet_right_side                     Kitchen Under Cabinet Side        857967db45534ea69fe7a3274721e378  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
zwave.kitchen_ceiling_dimmer                               zwave.kitchen_ceiling_dimmer      b831a81397a54d7c91b928320454b930  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
binary_sensor.kitchen_zooz_zse40_4_in_1_sensor_sensor      Kitchen Motion Sensor             3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_alarm_level        Kitchen Motion Alarm Level        3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_alarm_type         Kitchen Motion Alarm Type         3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_battery_level      Kitchen Motion Battery Level      3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_burglar            Kitchen Motion Burglar            3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_clock              Kitchen Motion Clock              3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_emergency          Kitchen Motion Emergency          3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_homehealth         Kitchen Motion HomeHealth         3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_sourcenodeid       Kitchen Motion SourceNodeId       3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_system             Kitchen Motion System             3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_luminance          Kitchen Motion Luminance          3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_relative_humidity  Kitchen Motion Relative Humidity  3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
zwave.kitchen_zooz_zse40_4_in_1_sensor                     Kitchen Motion                    3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
sensor.kitchen_zooz_zse40_4_in_1_sensor_temperature        Kitchen Motion Temperature        3b109d82986841a4bcad8d920053bd13  zwave       7b123350c2fc44f9ad6c146b0b335d40  None
~/Desktop ❯❯❯
ronytomen commented 4 years ago

Same issue, history command just doesn't seem to follow expected host and authentication configuration like other commands.

jshridha commented 3 years ago

I had to downgrade to 0.8.0 to get state history working again

johntdyer commented 3 years ago

Still and issue

transplier commented 3 years ago

Yep. Still happening.

$ hass-cli --version
hass-cli, version 0.9.4
$ hass-cli --sort-by last_changed state history --since 50m sensor.motion_sensor_basement_cave_temperature
Trying to locate Home Assistant on local network...
Found and using https://<redacted>.ui.nabu.casa as server
error: HomeAssistantCliError: Error while getting all states: 401: Unauthorized
Run with -x to see full exception information
$ hass-cli entity list | grep cave_temperature
sensor.motion_sensor_basement_cave_temperature                         Motion Sensor Basement Cave                            73b7c67a48011aebe67b43e7dcef83ab  deconz          b6bc1c797fd8d3e5b23721e3b5142aae  None
valleedelisle commented 2 years ago

Confirmed that #375 fixes the issue.