Mon problème
Bonjour,
Je débute avec home assistant et j’essaye de créer une custom card, J’ai cette erreur :
une idee ?
Merci d’avance.
SNas:volume1$ ls -la configuration.yaml ui-lovelace.yaml www/custom_mqtt_mode_card.js
-rwxrwxrwx+ 1 root root 475 May 25 17:03 configuration.yaml
-rwxrwxrwx+ 1 root root 1789 May 28 19:55 ui-lovelace.yaml
-rwxr-xr-x+ 1 root root 1871 May 25 15:56 www/custom_mqtt_mode_card.js
voici mon fichier de config/configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
mqtt: !include mqtt.yaml
lovelace:
mode: yaml
resources:
- url: /config/www/custom_mqtt_mode_card.js
type: js
config/ui-lovelace.yaml:
views:
- title: Home
cards:
- type: 'custom:custom-mqtt-mode-card'
entity: 'sensor.mqtt_entity'
state_topic: "zwave/41/64/0/mode"
command_topic: "zwave/41/64/0/mode/set"
modes:
- name: 'Off'
value: '0'
- name: 'Heat'
value: '1'
- name: 'Eco'
value: '11'
- name: 'Max'
value: '15'
- name: 'Manual'
value: '31'
mon config/www/custom_mqtt_mode_card.js:
class CustomMqttModeCard extends HTMLElement {
set hass(hass) {
if (!this.content) {
const card = document.createElement('ha-card');
this.content = document.createElement('div');
card.appendChild(this.content);
this.appendChild(card);
}
const entity = hass.states[this.config.entity];
const modes = this.config.modes;
const stateTopic = this.config.state_topic;
const commandTopic = this.config.command_topic;
if (entity) {
// Récupération du mode actuel via MQTT
hass.connection.subscribeMessage((message) => {
const currentMode = message;
this.content.innerHTML = `
<div>${entity.attributes.friendly_name}</div>
<div>Current Mode: ${currentMode}</div>
<select id="mode-select">
${modes.map(mode => `<option value="${mode.value}">${mode.name}</option>`)}
</select>
<button id="set-mode-button">Set Mode</button>
`;
}, stateTopic);
this.content.querySelector('#set-mode-button').addEventListener('click', () => {
const modeSelect = this.content.querySelector('#mode-select');
const selectedMode = modeSelect.value;
hass.callService('mqtt', 'publish', {
topic: commandTopic,
payload: selectedMode
});
});
}
}
setConfig(config) {
if (!config.entity) {
throw new Error('You need to define an entity');
}
if (!config.modes) {
throw new Error('You need to define modes');
}
if (!config.state_topic) {
throw new Error('You need to define a state topic');
}
if (!config.command_topic) {
throw new Error('You need to define a command topic');
}
this.config = config;
}
getCardSize() {
return 1;
}
}
customElements.define('custom-mqtt-mode-card', CustomMqttModeCard);
Ma configuration
System Information
version | core-2024.5.4 |
---|---|
installation_type | Home Assistant Container |
dev | false |
hassio | false |
docker | true |
user | root |
virtualenv | false |
python_version | 3.12.2 |
os_name | Linux |
os_version | 4.4.302+ |
arch | x86_64 |
timezone | Europe/Paris |
config_dir | /config |
Home Assistant Cloud
logged_in | false |
---|---|
can_reach_cert_server | ok |
can_reach_cloud_auth | ok |
can_reach_cloud | ok |
Dashboards
dashboards | 3 |
---|---|
resources | 1 |
views | 4 |
mode | yaml |
Recorder
oldest_recorder_run | 19 mai 2024 à 20:58 |
---|---|
current_recorder_run | 25 mai 2024 à 16:56 |
estimated_db_size | 221.63 MiB |
database_engine | sqlite |
database_version | 3.44.2 |