add type relay

This commit is contained in:
2025-11-11 10:10:22 +01:00
parent 86d1933c1f
commit 97ea853483
8 changed files with 120 additions and 5 deletions

View File

@@ -571,6 +571,8 @@
{% if device.type == "light" %}
Light
{% if device.features.brightness %}• Dimmbar{% endif %}
{% elif device.type == "relay" %}
Relay
{% elif device.type == "thermostat" %}
Thermostat
{% elif device.type == "contact" or device.type == "contact_sensor" %}
@@ -621,6 +623,21 @@
</div>
{% endif %}
{% elif device.type == "relay" %}
<div class="device-state">
<span class="state-label">Status:</span>
<span class="state-value off" id="state-{{ device.device_id }}">off</span>
</div>
<div class="controls">
<button
class="toggle-button off"
id="toggle-{{ device.device_id }}"
onclick="toggleDevice('{{ device.device_id }}')">
Einschalten
</button>
</div>
{% elif device.type == "thermostat" %}
<div class="thermostat-display">
<div class="temp-reading">
@@ -807,11 +824,13 @@
let eventSource = null;
let currentState = {};
let thermostatTargets = {};
let deviceTypes = {};
// Initialize device states
{% for room in rooms %}
{% for device in room.devices %}
{% if device.type == "light" %}
deviceTypes['{{ device.device_id }}'] = '{{ device.type }}';
{% if device.type == "light" or device.type == "relay" %}
currentState['{{ device.device_id }}'] = 'off';
{% elif device.type == "thermostat" %}
thermostatTargets['{{ device.device_id }}'] = 21.0;
@@ -822,6 +841,7 @@
// Toggle device state
async function toggleDevice(deviceId) {
const newState = currentState[deviceId] === 'on' ? 'off' : 'on';
const deviceType = deviceTypes[deviceId] || 'light';
try {
const response = await fetch(api(`/devices/${deviceId}/set`), {
@@ -830,7 +850,7 @@
'Content-Type': 'application/json'
},
body: JSON.stringify({
type: 'light',
type: deviceType,
payload: {
power: newState
}