Thiwanka01 commited on
Commit
2ffa909
·
verified ·
1 Parent(s): 690a8ae

Upload ai-energy-saver.tsx

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