aex351 / home-assistant-neerslag-card

Display Buienalarm and/or Buienradar data in a graph for Home Assistant.
30 stars 3 forks source link

ApexCharts card #10

Open Bergerie opened 3 years ago

Bergerie commented 3 years ago

Could the sensor output format be made compatible with the ApexCharts card, which would allow elaborate card option features.

aex351 commented 3 years ago

ApexCharts Card uses two types of input to plot a graph: 1) history data 2) data_generator (your own input - future data). The custom sensors (Buienalarm and Buienradar) are future data (not history data). This means you should be able to use the data_generator function and write your own input function for ApexCharts Card to convert the data from the custom sensors.

For the Neerslag Card / this project, the current focus is on converting the custom sensors (Buienalarm and Buienradar) in to a custom integration. This would make the setup of the Neerslag Card much easier as the user doesn't need to set-up custom sensors. In this proces I will have a look at storing history data, this probably would make the usage with other card (i.e. ApexCharts Card) easier. However, this still is history data and not future data.

watermarkhu commented 2 years ago

For anyone interested, below I've attached the javascript snippets to put into the data_generator field of the ApexCharts card. Since the data from the Buienradar and Buienalarm sensors are different, each has its own data_generator.

Buienradar:

return entity.attributes.data.split(" ").map(item => {
  return [moment(item.split("|")[1], 'HH:mm').valueOf(), Math.round(Math.pow(10, ((parseInt(item.split('|')[0] - 109) / 32))) * 100) / 100]
});

Buienalarm:

return entity.attributes.data.precip.map((item, index) => {
  return [moment.unix(entity.attributes.data.start).add(index*entity.attributes.data.delta, 's').valueOf(), item]
})