Replies: 1 comment
-
from homeassistant.helpers import template
import pendulum
from pendulum.tz import Timezone
datetime_now = template.now(hass)
log.debug(f"datetime_now: {type(datetime_now)} {datetime_now}")
datetimem_utcnow = template.utcnow(hass)
log.debug(f"datetimem_utcnow: {type(datetimem_utcnow)} {datetimem_utcnow}")
timezone_str = hass.config.time_zone
log.debug(f"timezone_str: {type(timezone_str)} {timezone_str}")
timestamp = datetime_now.timestamp()
log.debug(f"timestamp: {type(timestamp)} {timestamp}")
timezone = Timezone(hass.config.time_zone)
log.debug(f"timezone: {type(timezone)} {timezone}")
pendulum_now = pendulum.from_timestamp(timestamp, tz=timezone)
log.debug(f"pendulum_now: {type(pendulum_now)} {pendulum_now}") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Forgive my ignorance, I've gone from never having used home assistant to stumbling around python in the last year.
Objective
So I am combining the weather forecast and my 1/2 hourly variable electricity rates to compare to a temperature:efficiency curve to determine when the most cost effective time to run my hot water cycle on my heat pump is.
I have the code running correctly in VS Code and after wrapping the
requests.get
calls in a task executor I can retrieve the data I need from the 2 api calls in a hass pyscript jupyter notebook. Hooray.However I want to filter out historical data that is returned, I can't put my heat pump on in the past!
Packages
I import the following packages
Problem Code
The first line below is where I am falling over.
today=task.executor(datetime.datetime.now(rates.valid_from[0].tzinfo))
which works fine as below in Visual Studio Code/Python 3 notebook
I then use the variable
today
to filter out data from the past and do other stuff with pandas dataframesReturning the following error frpm jupyter hass pyscript notebook
Exception in <jupyter_0> line 14: today=task.executor(datetime.datetime.now(rates.valid_from[0].tzinfo)) ^ TypeError: function 2024-11-28 19:34:50.998470+00:00 is not callable by task.executor
Any pointers gratefully appreciated, thanks.
Beta Was this translation helpful? Give feedback.
All reactions