commit 52cb4a4b46e659840c967c12a1a605917371d351 Author: Tim Meneely Date: Sun May 24 21:07:04 2026 +0000 Trying to set up repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb102d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +lib +lib64 +__pycache__ diff --git a/.lock b/.lock new file mode 100644 index 0000000..e69de29 diff --git a/CACHEDIR.TAG b/CACHEDIR.TAG new file mode 100644 index 0000000..bc1ecb9 --- /dev/null +++ b/CACHEDIR.TAG @@ -0,0 +1 @@ +Signature: 8a477f597d28d172789f06886806bc55 \ No newline at end of file diff --git a/getfromha.py b/getfromha.py new file mode 100644 index 0000000..bac7ba2 --- /dev/null +++ b/getfromha.py @@ -0,0 +1,13 @@ +import os +from homeassistant_api import Client + +URL = 'http://homeassistant.local:8123/api' # Example: 'http://homeassistant.local:8123/api' +TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhOTFlYjJlNzc0OWI0M2VlODE5ZDE0MzdiNTY3YzcwMyIsImlhdCI6MTc3OTQxMTM5MiwiZXhwIjoyMDk0NzcxMzkyfQ.f2ULah3a1k4veHpcS9iPFMxR-wvKRb1oA5FbWAZyg9k' + +# Assigns the Client object to a variable and checks if it's running. +client = Client(URL, TOKEN) + +service = client.get_domain("light") # Gets the light service domain from Home Assistant + +service.turn_on(entity_id="light.my_living_room_light") +# Triggers the light.turn_on service on the entity `light.my_living_room_light` diff --git a/getweather.py b/getweather.py new file mode 100644 index 0000000..148b4a4 --- /dev/null +++ b/getweather.py @@ -0,0 +1,28 @@ +import python_weather +import datetime +import asyncio +import string + + +async def getweather() -> string: + async with python_weather.Client(unit=python_weather.IMPERIAL) as client: + theweather="" + # Fetch a weather forecast from a city. + weather = await client.get('Franklin Park PA') + #weather = await client.get('Pittsburgh') + # Fetch weather forecast for upcoming days. + for daily in weather: + if daily.date == datetime.datetime.today().date(): + theweather += "Today's forecast: High: "+str(daily.highest_temperature)+" F, Low: "+str(daily.lowest_temperature)+" F\n" + for hourly in daily: + if hourly.time.hour > 7 and hourly.time.hour < 19: + theweather+= " "+hourly.time.strftime("%I:%M %p")+" "+hourly.description+", "+str(hourly.temperature)+" F\n" + elif daily.date == datetime.datetime.today().date()+datetime.timedelta(days=1): + theweather += "Forecast for tomorrow: High: "+str(daily.highest_temperature)+" F, Low: "+str(daily.lowest_temperature)+" F\n" + + return theweather + +if __name__ == '__main__': + theweather = asyncio.run(getweather()) + print(theweather) + diff --git a/google_weather.py b/google_weather.py new file mode 100644 index 0000000..d8cb911 --- /dev/null +++ b/google_weather.py @@ -0,0 +1,93 @@ +import requests + +def get_current_weather(api_key, lat, lng, units="IMPERIAL"): + # The endpoint for current weather conditions + url = "https://weather.googleapis.com/v1/currentConditions:lookup" + + # Define the query parameters + params = { + "key": api_key, + "location.latitude": lat, + "location.longitude": lng, + "unitsSystem": units # Can be 'IMPERIAL' or 'METRIC' + } + + try: + # Make the HTTP GET request + response = requests.get(url, params=params) + + # Raise an exception for 4XX or 5XX status codes + response.raise_for_status() + + # Parse and return the JSON response + return response.json() + + except requests.exceptions.RequestException as e: + print(f"An error occurred: {e}") + return None + +def get_daily_forecast(api_key, lat, lng, days=2): + # The endpoint for daily forecasts + url = "https://weather.googleapis.com/v1/forecast/days:lookup" + + # Define the query parameters + params = { + "key": api_key, + "location.latitude": lat, + "location.longitude": lng, + "days": days, # Optional: defaults to 10 if not specified + "unitsSystem": "IMPERIAL" + } + + try: + # Make the HTTP GET request + response = requests.get(url, params=params) + + # Raise an exception if the request was unsuccessful + response.raise_for_status() + + # Parse the JSON response + data = response.json() + return data + + except requests.exceptions.RequestException as e: + print(f"An error occurred: {e}") + return None + +def get_google_weather(): +# Usage + API_KEY = "AIzaSyB42Vu94AoM8C6OHrF_iya5-crL8vPVjzs" + LATITUDE, LONGITUDE = 40.576511379423984, -80.07068759089107 + theweather = {} + + current_data = get_current_weather(API_KEY, LATITUDE, LONGITUDE) + + if current_data: + # Extracting specific fields from the response + condition = current_data.get("weatherCondition", {}).get("description", {}).get("text") + temp = current_data.get("temperature", {}) + feels_like = current_data.get("feelsLikeTemperature", {}) + humidity = current_data.get("relativeHumidity") + + theweather["current"] = (f"{condition}") + (f", {temp.get('degrees')}°F")\ + + (f", {humidity}%") + (f" hum., Feels like: {feels_like.get('degrees')}°F") + + forecast_data = get_daily_forecast(API_KEY, LATITUDE, LONGITUDE) + + if forecast_data: + day = forecast_data.get("forecastDays", [])[0] + max_temp = day.get("maxTemperature", {}).get("degrees") + min_temp = day.get("minTemperature", {}).get("degrees") + condition = day.get("daytimeForecast", {}).get("weatherCondition", {}).get("description", {}).get("text") + theweather["forecast_today"] = (f"{condition}") + (f", {min_temp}°F-{max_temp}°F") + day = forecast_data.get("forecastDays", [])[1] + max_temp = day.get("maxTemperature", {}).get("degrees") + min_temp = day.get("minTemperature", {}).get("degrees") + condition = day.get("daytimeForecast", {}).get("weatherCondition", {}).get("description", {}).get("text") + theweather["forecast_tomorrow"] = (f"{condition}") + (f", {min_temp}°F-{max_temp}°F") + + return theweather + +if __name__ == '__main__': + print("theweather",get_google_weather()) + diff --git a/imagegen.py b/imagegen.py new file mode 100644 index 0000000..7cf73b6 --- /dev/null +++ b/imagegen.py @@ -0,0 +1,32 @@ +from PIL import Image, ImageDraw, ImageFont +import datetime +import pytz +import asyncio +import google_weather +#from getweather import getweather +# create an image +out = Image.new("L", (800, 480),255) + +# get a font +fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",25) +fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",35) +# get a drawing context +d = ImageDraw.Draw(out) + +# create text +txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y %I:%M %p') +# draw multiline text +d.multiline_text((1, 1), txt1, font=fntBold, fill=0) +#txt2 = "This is the day that the LORD has made\nWe will rejoice and be glad in it." +#txt2 = asyncio.run(getweather()) +d.multiline_text((1, 35), "Weather:", font=fnt, fill=0) +weather = google_weather.get_google_weather() +txt2 = " Current: "+weather["current"] \ + +"\n Today's forecast: "+weather["forecast_today"] \ + +"\n Tomorrow: "+weather["forecast_tomorrow"] +d.multiline_text((1, 60), txt2, font=fnt, fill=0) +d.multiline_text((1, 135), "-----", font=fnt, fill=0) + +out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG") +#out.show() + diff --git a/pyvenv.cfg b/pyvenv.cfg new file mode 100644 index 0000000..ae75f92 --- /dev/null +++ b/pyvenv.cfg @@ -0,0 +1,5 @@ +home = /usr/bin +implementation = CPython +uv = 0.11.15 +version_info = 3.12.3 +include-system-site-packages = false diff --git a/testcurl.txt b/testcurl.txt new file mode 100644 index 0000000..374cd0a --- /dev/null +++ b/testcurl.txt @@ -0,0 +1,5 @@ +curl \ + -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhOTFlYjJlNzc0OWI0M2VlODE5ZDE0MzdiNTY3YzcwMyIsImlhdCI6MTc3OTQxMTM5MiwiZXhwIjoyMDk0NzcxMzkyfQ.f2ULah3a1k4veHpcS9iPFMxR-wvKRb1oA5FbWAZyg9k" \ + -H "Content-Type: application/json" http://192.168.1.192:8123/api/history/period?filter_entity_id=sensor.temperature + +