import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#Time setup
hours = np.arange(24)
time_labels = [f"{h}:00" for h in hours]
#Simulated hourly electricity prices (€/kWh)
#Real hourly electricity prices for April 28, 2025 (in €/kWh)
# Real hourly electricity prices for April 28, 2025 (in €/kWh)
prices = [
0.0750, 0.0385, 0.0221, 0.0125, 0.0150, 0.0158,
0.0372, 0.0560, 0.1704, 0.2382, 0.1791, 0.0888,
0.0436, 0.0377, 0.0283, 0.0331, 0.0450, 0.0687,
0.0888, 0.1314, 0.1106, 0.0699, 0.0601, 0.0319
]
#Power ratings (kW)
water_heater_power = 2.0 # Runs 3 hours/day
dishwasher_power = 1.5 # Runs 1 hour/day
#Run appliances in lowest-price hours
sorted_indices = np.argsort(prices)
#Pick cheapest 3 hours for water heater, 1 for dishwasher
water_heater_hours = sorted_indices[:3]
dishwasher_hour = sorted_indices[3]
#Create appliance schedule
schedule = pd.DataFrame({
"Hour": hours,
"Electricity Price (€/kWh)": prices,
"Water Heater (kW)": [water_heater_power if h in water_heater_hours else 0 for h in hours],
"Dishwasher (kW)": [dishwasher_power if h == dishwasher_hour else 0 for h in hours],
})
#Energy use and cost
schedule["Total Load (kW)"] = schedule["Water Heater (kW)"] + schedule["Dishwasher (kW)"]
schedule["Cost (€)"] = schedule["Total Load (kW)"] * schedule["Electricity Price (€/kWh)"]
#Total cost
total_cost = schedule["Cost (€)"].sum()
#Results
print(f"Total cost with optimized schedule: €{total_cost:.2f}")
display(schedule)
plt.figure(figsize=(12,5))
plt.plot(hours, prices, label="Electricity Price", marker='o')
plt.bar(hours, schedule["Total Load (kW)"], alpha=0.5, label="Appliance Load")
plt.title("Optimized Appliance Schedule")
plt.xlabel("Hour")
plt.ylabel("kW / €/kWh")
plt.xticks(hours)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Run to view results