Code Monkey home page Code Monkey logo

Comments (8)

slimcdk avatar slimcdk commented on July 23, 2024 1

I got this which is working except that the real datetime is hidden in an attribute and I've not found any graph that can display the data based of the attributes

  sensor:
    - platform: template
      sensors:
        preceding_day_energy_usage:
          unit_of_measurement: "kWh"
          friendly_name: Eloverblik Energy
          entity_id: group.eloverblik_energy
          value_template: >-
            {% set hour = now().hour %}
            {% set sensor = ['sensor.eloverblik_energy', hour, hour+1] | join('_') %}
            {{ states(sensor) }}
          attribute_templates:
            metering_start: >-
              {% set hour = now().hour %}
              {% set sensor = ['sensor.eloverblik_energy', hour, hour+1] | join('_') %}
              {% set datetimestr = [state_attr(sensor, 'Metering date'),'T', hour] | join('') %}
              {{ strptime(datetimestr, '%Y-%m-%dT%H') }}
            metering_end: >-
              {% set hour = now().hour %}
              {% set sensor = ['sensor.eloverblik_energy', hour, hour+1] | join('_') %}
              {% set datetimestr = [state_attr(sensor, 'Metering date'),'T', hour, ':59', ':59'] | join('') %}
              {{ strptime(datetimestr, '%Y-%m-%dT%H:%M:%S') }}

  group:
    eloverblik_energy:
      entities:
        - sensor.eloverblik_energy_0_1
        - sensor.eloverblik_energy_1_2
        - sensor.eloverblik_energy_2_3
        - sensor.eloverblik_energy_3_4
        - sensor.eloverblik_energy_4_5
        - sensor.eloverblik_energy_5_6
        - sensor.eloverblik_energy_6_7
        - sensor.eloverblik_energy_7_8
        - sensor.eloverblik_energy_8_9
        - sensor.eloverblik_energy_9_10
        - sensor.eloverblik_energy_10_11
        - sensor.eloverblik_energy_11_12
        - sensor.eloverblik_energy_12_13
        - sensor.eloverblik_energy_13_14
        - sensor.eloverblik_energy_14_15
        - sensor.eloverblik_energy_15_16
        - sensor.eloverblik_energy_16_17
        - sensor.eloverblik_energy_17_18
        - sensor.eloverblik_energy_18_19
        - sensor.eloverblik_energy_19_20
        - sensor.eloverblik_energy_20_21
        - sensor.eloverblik_energy_21_22
        - sensor.eloverblik_energy_22_23
        - sensor.eloverblik_energy_23_24

  automation:
    - alias: "Opdater Eloverblik sensor"
      id: update_eloverblik_sensor
      trigger:
        - platform: time_pattern
          minutes: '/60'
      action:
        - service: homeassistant.update_entity
          entity_id: sensor.preceding_day_energy_usage

from homeassistant-eloverblik.

JonasPed1 avatar JonasPed1 commented on July 23, 2024

I will consider adding such a sensor.

Can a template sensor not be used as a workaround?

from homeassistant-eloverblik.

LordMike avatar LordMike commented on July 23, 2024

I suppose a very long template could make do, or one fetching by name (where name includes current hour).... and then a cron/automation to update it each hour?

from homeassistant-eloverblik.

lillbass avatar lillbass commented on July 23, 2024

So, I am a NooB here... but I am trying to get the data from the sensors to show in Grafana, but that dosn't work because there is no time on the sensor, only a date... so i cannot compare my energy consumption whit the hourly energy prices - does this solve this problem and add's a time attribute to the sensor?

from homeassistant-eloverblik.

Rmh1978 avatar Rmh1978 commented on July 23, 2024

Hi @slimcdk

Nice work.

How do you compensate for the value of sensor.preceding_day_energy_usage is two days old in your view graph?

The meterdate is the 12-09-2022 but the value will be logged in the history for sensor.preceding_day_energy_usage
for today the 14-09-2022.

So if look at the graph in some days it will show the value metered the 12-09 on the graph as 14-09.

from homeassistant-eloverblik.

slimcdk avatar slimcdk commented on July 23, 2024

That is unfortunately a downside of HA. HA only works with realtime data as there is no option to manipulate the timestamp of data. Timestamps in attributes can however be used to display the correct date on graphs (ex Apexchart) but can not be used in the energy logging.

from homeassistant-eloverblik.

Rmh1978 avatar Rmh1978 commented on July 23, 2024

@slimcdk Thanks for pointing me to Apexcharts. Its awesome.

But i can´t figure out to replace the attribute data,

`type: custom:apexcharts-card
graph_span: 24h
now:
show: true
label: nu
header:
title: El forbrug pr time
show: true
show_states: true
series:

  • entity: sensor.preceding_day_energy_usage
    type: column
    name: Forbrug
    float_precision: 2
    group_by:
    func: avg
    duration: 60min`

Where it would be best to replace the data in the legend with:
{{ state_attr('sensor.preceding_day_energy_usage', 'metering_start')}}

Or replace "name: xxxx" with that attribute.

How did you solve it?

from homeassistant-eloverblik.

github-actions avatar github-actions commented on July 23, 2024

There hasn't been any activity on this issue recently. Issue will be marked as stale and closed after 7 days without any activity.

from homeassistant-eloverblik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.