Trying to set up repo
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
bin
|
||||
lib
|
||||
lib64
|
||||
__pycache__
|
||||
1
CACHEDIR.TAG
Normal file
1
CACHEDIR.TAG
Normal file
@@ -0,0 +1 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
13
getfromha.py
Normal file
13
getfromha.py
Normal file
@@ -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`
|
||||
28
getweather.py
Normal file
28
getweather.py
Normal file
@@ -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)
|
||||
|
||||
93
google_weather.py
Normal file
93
google_weather.py
Normal file
@@ -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())
|
||||
|
||||
32
imagegen.py
Normal file
32
imagegen.py
Normal file
@@ -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()
|
||||
|
||||
5
pyvenv.cfg
Normal file
5
pyvenv.cfg
Normal file
@@ -0,0 +1,5 @@
|
||||
home = /usr/bin
|
||||
implementation = CPython
|
||||
uv = 0.11.15
|
||||
version_info = 3.12.3
|
||||
include-system-site-packages = false
|
||||
5
testcurl.txt
Normal file
5
testcurl.txt
Normal file
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user