get_history error - takes one positional arguement but 2 were given
What happened?
When using hass.get_history() I get an error saying that I have used 2 positional arguements - but I haven't, I have used one (the entity ID), and a keyword arguement (start_time). I have tried using the days keyword arguement and get the same error. I am using python 3.11 on ubuntu 22.04, appdaemon 4.4.2
Version
4.4.2
Installation type
Python virtual environment
Relevant log output
2024-04-14 18:59:00.012400 WARNING pi3_check: ------------------------------------------------------------
TypeError: Hass.get_history() takes 1 positional argument but 2 were given
^^^^^^^^^^^^^^^^^^^^^
return await coro(*args, **kwargs)
File "/opt/appdaemon/lib/python3.11/site-packages/appdaemon/plugins/hass/hassapi.py", line 30, in coro_wrapper
raise self._exception
File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
^^^^^^^^^^^^^^^^^^^
return self.__get_result()
File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
result = future.result(self.AD.internal_function_timeout)
File "/opt/appdaemon/lib/python3.11/site-packages/appdaemon/utils.py", line 313, in run_coroutine_threadsafe
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
File "/opt/appdaemon/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
H1 = self.get_history('climate.play_room_radiator_1_heat_demand', start_time = history_start_time)
File "/opt/appdaemon/apps/heating.py", line 29, in run_check
funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"]))
File "/opt/appdaemon/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker
2024-04-14 18:59:00.011949 WARNING pi3_check: Traceback (most recent call last):
2024-04-14 18:59:00.009854 WARNING pi3_check: ------------------------------------------------------------
2024-04-14 18:59:00.009480 WARNING pi3_check: Worker Ags: {'id': 'f43d438c36f84b76b7ec134a0425c33c', 'name': 'pi3_check', 'objectid': 'a071accc286141dabdf1bdcfefc9bb38', 'type': 'scheduler', 'function': <bound method check_pi3.run_check of <heating.check_pi3 object at 0x7f8da826ed10>>, 'pin_app': True, 'pin_thread': 8, 'kwargs': {'interval': 86400, '__thread_id': 'thread-8'}}
2024-04-14 18:59:00.009051 WARNING pi3_check: Unexpected error in worker for App pi3_check:
2024-04-14 18:59:00.008573 WARNING pi3_check: ------------------------------------------------------------
Relevant code in the app or config file that caused the issue
history_start_time = datetime.now() - timedelta(hours=12)
H1 = self.get_history('climate.play_room_radiator_1_heat_demand', start_time = history_start_time)
Anything else?
No response
Use like this:
self.get_history(entity_id = "sensor", days = 5)
`history_start_time = datetime.now() - timedelta(hours=12)
H1 = self.get_history(entity_id="climate.play_room_radiator_1_heat_demand", start_time = history_start_time)`
you're using positional argument above for your sensor, that doesn't work
This will be fixed in the next release.
Example usage:
import json
from datetime import timedelta
from appdaemon.plugins.hass.hassapi import Hass
class History(Hass):
def initialize(self):
entity = 'climate.play_room_radiator_1_heat_demand'
history_start_time = self.get_now() - timedelta(hours=3)
history = self.get_history(entity, start_time=history_start_time)
# print the history nicely in the logs
self.log(json.dumps(history, indent=4, default=str))
This also works:
self.get_history(entity_id="sensor", days=5)
This is now working properly in the dev branch. Unfortunately the Home Assistant REST API doesn't support getting the history for a whole domain like that self.get_history(entity_id="sensor", days=5)