Seite 2 von 2
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 18:21
von lenschith
Das ist korrekt, in den Eingabeparametern wähle ich dann das Item aus das den Wert 'UNDEF' hat. Auch wenn ich das Item direkt in das Widget eingebe bekomme ich den Wert 'UNDEF'
Ich habe jetzt Testweise ein anderes Item eingefügt weil der DWD gerade ein Datum zur Unwetterwarnung gesendet hat. Aber auch hier ist das verhalten dasselbe.
Item:
Screenshot 2022-12-02 182029.png
Widget:
Screenshot 2022-12-02 181350.png
Es ist zwar nur eine kosmetische Sache, aber wäre schön wenn das ordentlich aussehen würde.
Hab ich da irgendwo ein generelles Problem?
Das ist ein Custom Widget - selbst erstellt.
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 19:44
von peter-pan
Ich hab das nochmal mit einem Standard "oh-label-item" getestet.
Das Ergebnis ist eigentlich ganz einfach:
Code: Alles auswählen
component: oh-label-item
config:
item: garbage_wastepaper_Title
title: Das ist ein Undef - Test
after: '=items.garbage_wastepaper_Title.state == "UNDEF" ? "undef" : "nicht undef"'
slots: null
In deinem "item" steht natürlich dein Item, das den "UNDEF" - Wert ausgibt. Nun nimmst du noch eine Zeile hinzu (after) und da gibst du dann deine expression ein. Vielleicht änderst du die Bedingung noch etwas ab (!= "UNDEF"), dann kannst du nach dem" ?" dein Item eingeben und nach dem ":" deine Leerzeichen.
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 21:30
von lenschith
Super, vielen Dank. So wie das aussieht klappt das jetzt bei mir. Wo bekommt ihr denn immer diese Infos her. Ich habe ohne Ende gesucht aber diese Lösung hab ich nirgendwo gesehen. Gibts denn da irgendwo Tutorials um das zu lernen bzw. besser zu verstehen?
So sieht mein Script jetzt aus:
Code: Alles auswählen
- component: oh-label-item
config:
icon: f7:clock_fill
iconColor: green
item: =(props.validTo)
after: '=items[props.validTo].state != "UNDEF" ? items[props.validTo].displayState : " "'
title: "Gültig bis: "
Ich hoffe ich habe das richtig angepasst. Bei meinen Tests hat es funktioniert.
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 21:52
von peter-pan
Ja, so in etwa sollte es funktionieren. Ich weiss jetzt nicht, ob du das ".displayState" unbedingt hier brauchst. Hast du eine Formatierung (Pattern-Metadata) in diesem Item ?
Es gibt schon ein paar Dokus, z.B.
hier und
hier. Wenn es um CSS geht, findest du
hier vielleicht noch einen Rat.
Ich versuch halt das ein oder andere aus den Yaml-Codes der Standard-Widgets abzuleiten. Dann schau ich auch oft im internationalen Forum vorbei und probier dann halt mit dem was ich da finde das ein oder andere aus.
Aber ich muss erlich sagen, so richtig verstanden habe ich das nicht. Ich mach's halt auch mit "Try and Error".
Edit: Wie sieht denn eigentlich dein Eingabe-Feld (Eingabe-Parameter) für dein "props...." aus ? Irgendwie kommt mir das noch etwas komisch vor.
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 22:17
von lenschith
ja, das displayState brauche ich an der Stelle, weil ich die DateTime in der StateDescription ändere, damit das lesbarer ist.
Was meinst du mit den props?
ich kann hier mal mein Widget Script posten damit du das ganze siehst. Bin dankbar für Tipps falls ich da was falsch habe.
Aber ich wähle dann einfach das Item mit dem DateTime Wert aus. Vom DWD Unwetter Binding.
Code: Alles auswählen
- context: item
description: Warnung Gültig bis
label: Valid to
name: validTo
required: false
type: TEXT
Code: Alles auswählen
uid: Unwetter-Wetter
tags:
- dwd
- lenschi.th
- unwetterwarnung
- wettervorhersage
props:
parameters:
- context: item
description: Warnung Titel
label: Headline
name: headline
required: true
type: TEXT
- context: item
description: Warnung Type
label: Type
name: type
required: true
type: TEXT
- context: item
description: Warnung Schweregrad
label: Severity
name: severity
required: true
type: TEXT
- context: item
description: Warnung Gültig ab
label: Valid from
name: validFrom
required: false
type: TEXT
- context: item
description: Warnung Gültig bis
label: Valid to
name: validTo
required: false
type: TEXT
- context: item
description: Warnung Beschreibung
label: Description
name: description
required: true
type: TEXT
- context: item
description: Anweisung
label: Instruction
name: anweisung
required: false
type: TEXT
parameterGroups: []
timestamp: Dec 2, 2022, 3:48:09 PM
component: f7-card
config:
style:
border-radius: 5px
box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
class:
- padding: 0px
margin-left: 0px
margin-right: 0px
noShadow: false
title: =(items[props.headline].state).replace('keine Warnung','Wetter')
slots:
content:
- component: oh-list-card
config:
noBorder: true
noShadow: true
outline: true
slots:
default:
- component: oh-list-item
config:
badge: =(Math.round(items.OneCallAPIweatherandforecast_ForecastToday_Mintemperature.state.split(' ')[0] * 1) / 1 + '° / ' + Math.round(items.OneCallAPIweatherandforecast_ForecastToday_Maxtemperature.state.split(' ')[0] * 1) / 1 + '°')
badgeColor: gray
icon: "=(items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '01d') ? 'f7:sun_max' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '01n') ? 'f7:moon_stars' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '02d') ? 'f7:cloud_sun' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '02n') ? 'f7:cloud_moon' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '03d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '03n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '04d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '04n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '09d') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '09n') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '10d') ? 'f7:cloud_sun_rain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '10n') ? 'f7:cloud_moon_rain' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '11d') ? 'f7:cloud_sun_bolt' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '11n') ? 'f7:cloud_moon_bolt' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '13d') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '13n') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '50d') ? 'f7:cloud_fog' : (items.OneCallAPIweatherandforecast_ForecastToday_Iconid.state === '50n') ? 'f7:cloud_fog' : '?'"
iconColor: gray
title: Wetter heute
- component: oh-list-item
config:
badge: =(Math.round(items.OneCallAPIweatherandforecast_ForecastTomorrow_Mintemperature.state.split(' ')[0] * 1) / 1 + '° / ' + Math.round(items.OneCallAPIweatherandforecast_ForecastTomorrow_Maxtemperature.state.split(' ')[0] * 1) / 1 + '°')
badgeColor: gray
icon: "=(items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '01d') ? 'f7:sun_max' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '01n') ? 'f7:moon_stars' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '02d') ? 'f7:cloud_sun' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '02n') ? 'f7:cloud_moon' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '03d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '03n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '04d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '04n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '09d') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '09n') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '10d') ? 'f7:cloud_sun_rain' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '10n') ? 'f7:cloud_moon_rain' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '11d') ? 'f7:cloud_sun_bolt' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '11n') ? 'f7:cloud_moon_bolt' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '13d') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '13n') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '50d') ? 'f7:cloud_fog' : (items.OneCallAPIweatherandforecast_ForecastTomorrow_Iconid.state === '50n') ? 'f7:cloud_fog' : '?'"
iconColor: gray
title: Wetter morgen
- component: oh-list-item
config:
badge: =(items[props.severity].state).replace('keine Warnung','')
badgeColor: '=items[props.severity].state === "LEICHT" ? "yellow" : items[props.severity].state === "MITTEL" ? "violett" : items[props.severity].state === "SCHWER" ? "orange" : items[props.severity].state === "SEHR SCHWER!" ? "red" : items[props.severity].state === "keine Warnung" ? "blue" : "white"'
icon: "=(items.OneCallAPIweatherandforecast_Current_Iconid.state === '01d') ? 'f7:sun_max' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '01n') ? 'f7:moon_stars' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '02d') ? 'f7:cloud_sun' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '02n') ? 'f7:cloud_moon' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '03d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '03n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '04d') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '04n') ? 'f7:cloud' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '09d') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '09n') ? 'f7:cloud_heavyrain' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '10d') ? 'f7:cloud_sun_rain' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '10n') ? 'f7:cloud_moon_rain' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '11d') ? 'f7:cloud_sun_bolt' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '11n') ? 'f7:cloud_moon_bolt' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '13d') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '13n') ? 'f7:cloud_snow' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '50d') ? 'f7:cloud_fog' : (items.OneCallAPIweatherandforecast_Current_Iconid.state === '50n') ? 'f7:cloud_fog' : items[props.severity].state === 'keine Warnung' ? 'f7:checkmark_2' : '?'"
iconColor: '=items[props.severity].state === "LEICHT" ? "yellow" : items[props.severity].state === "MITTEL" ? "violett" : items[props.severity].state === "SCHWER" ? "orange" : items[props.severity].state === "SEHR SCHWER!" ? "red" : items[props.severity].state === "keine Warnung" ? "blue" : "white"'
title: =items[props.type].state
- component: oh-label-item
config:
icon: f7:clock
iconColor: red
item: =(props.validFrom)
after: '=items[props.validFrom].state != "UNDEF" ? items[props.validFrom].displayState : " "'
title: "Gültig ab:"
- component: oh-label-item
config:
icon: f7:clock_fill
iconColor: green
item: =(props.validTo)
after: '=items[props.validTo].state != "UNDEF" ? items[props.validTo].displayState : " "'
title: "Gültig bis: "
- component: f7-card
config:
content: =(items[props.description].state).replace('keine Warnung','')
noBorder: false
noShadow: true
outline: false
- component: f7-card-footer
slots:
default:
- component: Label
config:
style:
color: red
font-size: 15px
font-weight: 800
text-align: center
text: =(items[props.anweisung].state).replace('keine Warnung','')
Re: Widget UNDEF entfernen
Verfasst: 2. Dez 2022 23:00
von peter-pan
lenschith hat geschrieben: ↑2. Dez 2022 22:17
Was meinst du mit den props?
Passt alles. Da hab ich mich wohl vertan.
Wie steuerst du denn deine AVM-Thermostate ?
Re: Widget UNDEF entfernen
Verfasst: 3. Dez 2022 09:05
von lenschith
Die Thermostate steuere ich eigentlich kaum über OH. Ich nutze hier hauptsächlich die Vorlagen die ich auf der Fritz!Box erstellt habe und schalte die über die Sitemap. Oder ändere mal den Modus über die Sitemap.
Lese zum Großteil nur die Temperatur, Batterie Status oder Fenster auf aus und versende dann Notifications beim über/unterschreiten von Schwellwerten.
Re: Widget UNDEF entfernen
Verfasst: 5. Mär 2023 08:58
von Mclupo
scotty hat geschrieben: ↑1. Dez 2022 15:22
diese Function ändert UNDEF in "-"
Code: Alles auswählen
(function(i) {
var state = ""
var value = i
if(value == "UNDEF") {
state = "-";
} else {
state = value;
}
return state;
})(input)
ich habe mal diesen Beitrag nochmal hervorgeholt. Auch in der UI erstellte items kann man mit dieser funktion sehr gut beeinflussen.
1) js file in TRANSFORM mit name file.js erstellen
2) in der UI das gewünschte item aufrufen und dann den angezeigten entsprechenden channel link aufrufen
3) das Profil JS anklicken. Wenn man weiter unten mit dem Mauszeiger auf das Feld Dateiname klickt, werden einem die vorhandenen Files.js angezeigt und das gewünschte kann ausgewählt werden.