Spaces:
No application file
No application file
File size: 4,080 Bytes
2ffa909 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
import React, { useState } from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import {
Home,
Thermometer,
Zap,
Lightbulb,
Clock,
Activity
} from 'lucide-react';
const AIEnergySaver = () => {
// State management for various energy-saving features
const [temperature, setTemperature] = useState(72);
const [energySavings, setEnergySavings] = useState(0);
const [deviceStatus, setDeviceStatus] = useState({
lights: false,
heating: false,
cooling: false,
smartAppliances: false
});
// Simulated energy optimization function
const optimizeEnergy = () => {
// Simulate smart energy-saving adjustments
const savedPercentage = Math.floor(Math.random() * 15) + 5; // 5-20% savings
setEnergySavings(prev => prev + savedPercentage);
// Smart device adjustments
setDeviceStatus(prev => ({
lights: Math.random() > 0.5,
heating: temperature > 70 ? false : prev.heating,
cooling: temperature < 70 ? false : prev.cooling,
smartAppliances: Math.random() > 0.3
}));
};
// Temperature adjustment functions
const adjustTemperature = (change) => {
setTemperature(prev => {
const newTemp = prev + change;
return Math.max(60, Math.min(newTemp, 80)); // Limit range
});
};
return (
<div className="p-4 max-w-md mx-auto">
<Card className="w-full">
<CardHeader className="bg-green-50">
<CardTitle className="flex items-center">
<Home className="mr-2" /> AI Energy Saver
</CardTitle>
</CardHeader>
<CardContent className="space-y-4 p-4">
{/* Temperature Control */}
<div className="flex items-center justify-between">
<div className="flex items-center">
<Thermometer className="mr-2" />
<span>Temperature: {temperature}°F</span>
</div>
<div className="flex space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => adjustTemperature(-1)}
>
-
</Button>
<Button
variant="outline"
size="sm"
onClick={() => adjustTemperature(1)}
>
+
</Button>
</div>
</div>
{/* Energy Savings */}
<div className="flex items-center">
<Zap className="mr-2" />
<span>Total Energy Savings: {energySavings}%</span>
</div>
{/* Device Status */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<div className="flex items-center">
<Lightbulb className="mr-2" />
<span>Lights</span>
</div>
<span
className={`text-sm font-bold ${
deviceStatus.lights ? 'text-green-600' : 'text-red-600'
}`}
>
{deviceStatus.lights ? 'Optimized' : 'Standard'}
</span>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center">
<Clock className="mr-2" />
<span>Smart Appliances</span>
</div>
<span
className={`text-sm font-bold ${
deviceStatus.smartAppliances ? 'text-green-600' : 'text-red-600'
}`}
>
{deviceStatus.smartAppliances ? 'Active' : 'Inactive'}
</span>
</div>
</div>
{/* Optimize Button */}
<Button
className="w-full"
onClick={optimizeEnergy}
>
<Activity className="mr-2" />
Optimize Energy Usage
</Button>
</CardContent>
</Card>
</div>
);
};
export default AIEnergySaver;
|