Add derivative displays

master
Kuba Orlik 3 months ago
parent a05d66fb43
commit 6c7ca53703

@ -34,6 +34,11 @@ async function with_unit(s: HA_RESPONSE | Promise<HA_RESPONSE>) {
return `${s.state}${s.attributes.unit_of_measurement as string}`; return `${s.state}${s.attributes.unit_of_measurement as string}`;
} }
async function arrow(entity: string) {
const number = parseFloat((await get_state(entity)).state);
return number < 0 ? "↓" : number > 0 ? "↑" : "=";
}
export default new (class DashboardPage extends StatefulPage<State, typeof actions> { export default new (class DashboardPage extends StatefulPage<State, typeof actions> {
actions = actions; actions = actions;
@ -49,18 +54,8 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
} }
} }
render(ctx: BaseContext, state: State, inputs: Record<string, string>) { async render(ctx: BaseContext, state: State, inputs: Record<string, string>) {
const date = new Date(); const date = new Date();
const stuff = [
{ label: "Temperatura na balkonie", entity: "input_number.balkon_average" },
{ label: "Temperatura w salonie", entity: "sensor.ewelink_th01_temperature" },
{ label: "Wilgotność w salonie", entity: "sensor.ewelink_th01_humidity" },
{ label: "Temperatura na strychu", entity: "sensor.strych_temperature_3" },
{
label: "Docelowa temp. na strychu",
entity: "input_number.strych_target_temperature",
},
];
return ( return (
<div style="font-size: 2rem"> <div style="font-size: 2rem">
@ -70,14 +65,56 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
</div> </div>
<table style="margin: 0 auto"> <table style="margin: 0 auto">
<tbody> <tbody>
{stuff.map(({ label, entity }) => (
<tr> <tr>
<td style="text-align: right">{label}:</td> <td style="text-align: right">Temperatura na balkonie:</td>
<td>
<strong>
{with_unit(get_state("input_number.balkon_average"))}
{arrow("sensor.balkon_temperature_derivative")}
</strong>
</td>
</tr>
<tr>
<td style="text-align: right">Temperatura w salonie:</td>
<td>
<strong>
{with_unit(
get_state("sensor.ewelink_th01_temperature")
)}
{arrow("sensor.temperatura_w_salonie_derivative")}
</strong>
</td>
</tr>
<tr>
<td style="text-align: right">Wilgotność w salonie</td>
<td> <td>
<strong>{with_unit(get_state(entity))}</strong> <strong>
{with_unit(get_state("sensor.ewelink_th01_humidity"))}
</strong>
</td> </td>
</tr> </tr>
))} <tr>
<td style="text-align: right">Temperatura na strychu</td>
<td>
<strong>
{with_unit(get_state("sensor.strych_temperature_3"))}
{arrow("sensor.strych_temperature_derivative")}
</strong>
</td>
</tr>
{/*
<tr>
<td style="text-align: right">Docelowa temp. na strychu</td>
<td>
<strong>
{with_unit(
get_state(
"input_number.strych_target_temperature"
)
)}
</strong>
</td>
</tr>*/}
</tbody> </tbody>
</table> </table>
{this.makeActionButton(state, { {this.makeActionButton(state, {

Loading…
Cancel
Save