Anashost / MY-HA-DASH

81 stars 8 forks source link

[ASK][REQ] Energy Meter Page #10

Open muktheo opened 6 months ago

muktheo commented 6 months ago

Hi Anas, I'm Muktheo who has already commented in your youtube video regarding the plug and energy pages :)

Maybe if you already have some spare time, you can help me with writing the the steps and all dependencies on that section.

thank you so much. Regards

Anashost commented 6 months ago

Sure i will try to do that by tomorrow.

Edit: Note that the price of kw in my case is just fixed one, as in my energy contract i get a fixed price each year. So not sure if my custom sensors will work dynamically with a dynamic kw price sensor (probably not).

But kw usage should work as long as your plugs provides current_consumption attribute.

So confirm if you still want me to write the steps and yaml.

muktheo commented 6 months ago

Hi, sorry for late reply, Coincidentally my kWh meter price is also fixed. I didnt have peak tariff/low tariff something like that. 😄

So you can still help me with your steps, cusom sensors, and codes, please..

Thanks

Anashost commented 6 months ago

No worries,

So my plugs entity names are switch.plug_1_local and so on, better rename yours the same so could copy paste and all will just work, or you can just adapt and make changes.

You need the following for every Plug:

  p1_day_usage:
    source: sensor.p1_consumption_in_kwh
    cycle: daily

  p1_month_usage:
    source: sensor.p1_consumption_in_kwh
    cycle: monthly

  p1_year_usage:
    source: sensor.p1_consumption_in_kwh
    cycle: yearly
  - platform: template
    sensors:
      plug_1_local_power:
        friendly_name: "p1 consumption in Watt"
        unit_of_measurement: 'W'
        device_class: power
        value_template: "{{ states.switch.plug_1_local.attributes.current_consumption }}"
  - platform: integration
    source: sensor.plug_1_local_power
    name: p1_consumption_in_kwh
    method: left
    round: 2
    unit_prefix: k
  - platform: template
    sensors:
      p1_day_usage_cost:
        friendly_name: 'p1 day usage cost'
        value_template: >
         {% if states('sensor.p1_day_usage') | float(default=0) > 0 and states('sensor.manual_energy_price') | float(default=0) > 0 %}
           {{ (states('sensor.p1_day_usage') | float * states('sensor.manual_energy_price') | float ) | round(2) }}€
         {% else %}
           0.0€
         {% endif %}

  - platform: template
    sensors:
      p1_month_usage_cost:
        friendly_name: 'p1 month usage cost'
        value_template: >
         {% if states('sensor.p1_month_usage') | float(default=0) > 0 and states('sensor.manual_energy_price') | float(default=0) > 0 %}
           {{ (states('sensor.p1_month_usage') | float * states('sensor.manual_energy_price') | float ) | round(2) }}€
         {% else %}
           0.0€
         {% endif %}

  - platform: template
    sensors:
      p1_year_usage_cost:
        friendly_name: 'p1 year usage cost'
        value_template: >
         {% if states('sensor.p1_year_usage') | float(default=0) > 0 and states('sensor.manual_energy_price') | float(default=0) > 0 %}
           {{ (states('sensor.p1_year_usage') | float * states('sensor.manual_energy_price') | float ) | round(2) }}€
         {% else %}
           0.0€
         {% endif %}

Also create this sensor for the energy price. In my case its just a fixed one with price: 0.4€

  - platform: template
    sensors:
      manual_energy_price:
        friendly_name: 'manual energy price'
        value_template: >
          {{ 0.4 }}
Anashost commented 6 months ago

Tell me if everything above works ok, to send you the cards configurations and automations.

muktheo commented 6 months ago

hi bro,

I've created all custom sensors and I saw the entity value already running, so..lets continue

Anashost commented 6 months ago

Nice, i will write the steps and yaml today 👍🏻

Anashost commented 6 months ago

Requirements:

usage card:

type: conditional
conditions:
  - entity: input_boolean.p1_drop_down_toggle
    state: 'on'
card:
  aggregate_func: max
  color_thresholds:
    - color: '#00ccff'
      value: 15
    - color: '#00ccff'
      value: 7
    - color: '#00ccff'
      value: 5
    - color: '#00ccff'
      value: 3
    - color: '#00ccff'
      value: 0
  color_thresholds_transition: hard
  entities:
    - sensor.p1_day_usage
  group_by: date
  hour24: true
  hours_to_show: 168
  name: RaspBerry Consumption
  show:
    fill: fade
    graph: bar
    labels: false
  smoothing: false
  type: custom:mini-graph-card

usage/cost/live card:

type: conditional
conditions:
  - entity: input_boolean.p1_drop_down_toggle
    state: 'on'
card:
  type: entities
  entities:
    - entity: sensor.p1_day_usage
      name: Today
    - entity: sensor.p1_day_usage_cost
      name: Today Cost
      icon: mdi:cash-multiple
    - entity: sensor.p1_month_usage
      name: This month
    - entity: sensor.p1_month_usage_cost
      name: This month Cost
      icon: mdi:cash-multiple
    - entity: sensor.p1_year_usage
      name: This year
    - entity: sensor.p1_year_usage_cost
      name: This year Cost
      icon: mdi:cash-multiple
    - entity: sensor.plug_1_local_power
      name: Live
  state_color: true
  show_header_toggle: true
  theme: Mushroom Shadow
muktheo commented 6 months ago

thank you!

it works flawesly. perhaps you forgot about the automation steps from the toogles, but dont worry, I've already find it from another issue thread in this section 😄

Anashost commented 6 months ago

Glad it works, Here's the automations to double check.

alias: "plugs stats view (toggle)"
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.p1_drop_down_toggle
    from: "off"
    to: "on"
    id: p1
  - platform: state
    entity_id:
      - input_boolean.p2_drop_down_toggle
    from: "off"
    to: "on"
    id: p2
  - platform: state
    entity_id:
      - input_boolean.p3_drop_down_toggle
    from: "off"
    to: "on"
    id: p3
  - platform: state
    entity_id:
      - input_boolean.p4_drop_down_toggle
    from: "off"
    to: "on"
    id: p4
  - platform: state
    entity_id:
      - input_boolean.p5_drop_down_toggle
    from: "off"
    to: "on"
    id: p5
  - platform: state
    entity_id:
      - input_boolean.p6_drop_down_toggle
    from: "off"
    to: "on"
    id: p6
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: p1
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p3_drop_down_toggle
                - input_boolean.p2_drop_down_toggle
                - input_boolean.p4_drop_down_toggle
                - input_boolean.p5_drop_down_toggle
                - input_boolean.p6_drop_down_toggle
      - conditions:
          - condition: trigger
            id: p2
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p1_drop_down_toggle
                - input_boolean.p3_drop_down_toggle
                - input_boolean.p4_drop_down_toggle
                - input_boolean.p5_drop_down_toggle
                - input_boolean.p6_drop_down_toggle
      - conditions:
          - condition: trigger
            id: p3
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p1_drop_down_toggle
                - input_boolean.p2_drop_down_toggle
                - input_boolean.p4_drop_down_toggle
                - input_boolean.p5_drop_down_toggle
                - input_boolean.p6_drop_down_toggle
      - conditions:
          - condition: trigger
            id: p4
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p1_drop_down_toggle
                - input_boolean.p2_drop_down_toggle
                - input_boolean.p3_drop_down_toggle
                - input_boolean.p5_drop_down_toggle
                - input_boolean.p6_drop_down_toggle
      - conditions:
          - condition: trigger
            id: p5
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p1_drop_down_toggle
                - input_boolean.p2_drop_down_toggle
                - input_boolean.p3_drop_down_toggle
                - input_boolean.p4_drop_down_toggle
                - input_boolean.p6_drop_down_toggle
      - conditions:
          - condition: trigger
            id: p6
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id:
                - input_boolean.p1_drop_down_toggle
                - input_boolean.p2_drop_down_toggle
                - input_boolean.p3_drop_down_toggle
                - input_boolean.p4_drop_down_toggle
                - input_boolean.p5_drop_down_toggle
mode: single