damianeickhoff / HaCasa

Custom theme and cards for Home Assistant
https://damianeickhoff.github.io/HaCasa/
MIT License
103 stars 10 forks source link

Clean up code #4

Open damianeickhoff opened 8 months ago

damianeickhoff commented 8 months ago

All the code need a pretty good swipe through.

TouTje commented 8 months ago

Thank you for your work. To clean up the code for the weather forecast you could edit the following code. name: '[[[ return states["sensor.weather_forecast_1"].state ]]]' to:

name: >-
  [[[
    var days = ['Zon', 'Ma', 'Di', 'Woe', 'Do', 'Vrij', 'Zat'];
    var currentDate = new Date(states[entity.entity_id].attributes.forecast[0].datetime);
    currentDate.setDate(currentDate.getDate());
    return days[currentDate.getDay()];
  ]]]

It is a little more code, but his makes adding an extra sensor unnecessary and ensures a correct link to the correct weather forecast.