HA

Start Ubuntu live usb pind

Se hvor data kan gemmes (sudo fdisk -l)

Hent nyeste HA med wget (hent link til nyeste her: https://www.home-assistant.io/installation/generic-x86-64)


installere med:
sudo xz -dc “imagenavn” | sudo dd of=/dev/sda bs=4M conv=fsync


Login til HA
Opret bruger
ret din egen bruger til “advanceret”

og opret en kunde bruger

Tilføj HACS: https://hacs.xyz/docs/setup/download/

Tilføj File editor og Tailscale, som standart apps i HA

Tailscale – HUSK at slå key expire off

Installere “Energi service data” & “apexcharts”

I filen “configuration.yaml”, tilføjes:

homeassistant:
  packages: !include_dir_named packages

Her efter oprettes der en mappe med navnet “packages”

og der filføjes en fil: calculator.yaml


  input_datetime:
    calculator_end_time:
      name: Slut tid
      has_date: false
      has_time: true    
      
    calculator_start_time:
      name: Start tid
      has_date: false
      has_time: true

    calculator_duration:
      name: Varighed
      has_date: false
      has_time: true

  input_number:
    calculator_kilowatt:
      name: Consumption kW
      icon: mdi:clock-start
      min: 0
      max: 30
      step: 0.01
      mode: box


  template:
    - sensor:
        - name: "Price Calculator"
          unique_id: 75a51b09
          attributes:
            start_times: >
              {# Configuration #}

              {# Name of Energi Price Sensor #}
              {% set sensor_name = "sensor.energi_data_service" %}

              {# Consumption in kW #}
              {% set consumption = states("input_number.calculator_kilowatt") | float %}

              {# Duration of charging, washing, etc.  #}
              {% set input_duration = today_at(states("input_datetime.calculator_duration")) %}
              {% set duration = timedelta(hours = input_duration.hour, minutes = input_duration.minute) %} 

              {# First possible time to start. Default now() #}
              {% set start_time = now() %}       

              {# Deadline for when the operation should be finished (For example departure time). 
              Default tomorrow at 23:59:59 if tomorrows prices are available, otherwise today at 23:59:59 #}
              {% set end_time = today_at(states("input_datetime.calculator_end_time")) + timedelta(days = 1 if today_at(states("input_datetime.calculator_end_time")) < now() else 0) %}

              {# Macros #}
              {%- macro date_to_index(date) -%}{{(date.hour + (date.date() - now().date()).days * 24)}}{%- endmacro -%}{# as datetime? #}
              {%- macro index_to_date(index) -%}{{today_at("00:00") + timedelta(hours = index)}}{%- endmacro -%}{# as int? #}

              {# All available prices from price sensor #}
              {% set prices_raw = state_attr(sensor_name, "raw_today") + state_attr(sensor_name, "raw_tomorrow") | selectattr('value', '!=', none) | list %}

              {# End time can not be later than the available price data #}
              {% set end_time = [end_time, (prices_raw | last).hour + timedelta(hours=1)] | min %}

              {% set start_hour = date_to_index(start_time) | int %}
              {% set end_hour = 2 + date_to_index(end_time - duration) | int %}

              {# All prices within timerange #}
              {% set prices = prices_raw[start_hour:end_hour] %}

              {# namespace to hold values #}
              {% set ns = namespace(start_times = []) %}
              {% for price in prices %}
                {% set item = namespace(start = price.hour, end = price.hour + duration) %}
                {% if loop.first %}
                  {% set item.start = start_time %}
                  {% set item.end = start_time + duration %}
                {% elif loop.last %}
                  {% set item.start = end_time - duration %}
                  {% set item.end = end_time %}
                {% endif %}
                {% set item.value = 0%}
                {% for index in range(date_to_index(item.start) | int, date_to_index(item.end) | int + 1) %}
                    {% set hour_duration = ([item.end, index_to_date(index + 1) | as_datetime] | min - [item.start, index_to_date(index) | as_datetime] | max).total_seconds() / 60 / 60 %}
                    {% if hour_duration > 0 %}
                      {% set item.value = item.value + (prices_raw[index].price * hour_duration) %}
                    {% endif %}                    
                {% endfor %}
                {% set ns.start_times = ns.start_times + [{'start': item.start | string, 'end': item.end | string, 'value': (item.value * consumption) | round (2)}] %}
              {% endfor -%}               
              {# Sort items by value or start #}
              {{ns.start_times | sort(attribute='start') | tojson}}

          state: >
            Calculating...?

        - name: "Price Calculator Price now"
          unique_id: 3d357de0
          state: >
            {{ state_attr("sensor.price_calculator", "start_times")[0].value | round (2)}}

        - name: "Price Calculator Cheapest Time"
          unique_id: fa95a6f8
          state: >
            {{ (state_attr("sensor.price_calculator", "start_times") | sort(attribute='value'))[0].start }}
          attributes:
            countdown: >
              {% set value = states("sensor.price_calculator_cheapest_time") | as_datetime %}
              {% if value > now() -%}
              start om {{'%02d' % ((value - now()).total_seconds() / 60 / 60) | round(0, 'floor')}}:{{'%02d' % ((value - now()).total_seconds() / 60 % 60) | round(0, 'floor')}}
              {%- else -%}start nu{%- endif %}

        - name: "Price Calculator Cheapest Price"
          unique_id: e725fdd4
          state: >
            {{ (state_attr("sensor.price_calculator", "start_times") | sort(attribute='value'))[0].value | round (2)}}

    - binary_sensor:
        - name: "Price Calculator Is cheapest"
          unique_id: 26d33c17
          state: >
            {{ (state_attr("sensor.price_calculator", "start_times") | sort(attribute='value'))[0] == state_attr("sensor.price_calculator", "start_times")[0]}}

Følgende oprettes op HA’s første skærm: (Raw edit)

title: Hjem
views:
  - theme: Backend-selected
    title: Home
    badges: []
    cards:
      - type: vertical-stack
        cards:
          - type: entity
            entity: sensor.price_calculator_cheapest_time
            attribute: countdown
            name: 'Start tid:'
            icon: mdi:clock-digital
          - type: entities
            entities:
              - entity: binary_sensor.price_calculator_is_cheapest
                name: Billigst nu
                icon: mdi:currency-usd
              - entity: sensor.price_calculator_price_now
                icon: mdi:cash-100
                name: Pris nu
              - entity: sensor.price_calculator_cheapest_price
                name: Billigste pris
                icon: mdi:cash-100
              - entity: sensor.price_calculator_cheapest_time
                name: Billigste tidspunkt
                icon: mdi:clock
          - type: entities
            entities:
              - entity: input_datetime.calculator_start_time
              - entity: input_datetime.calculator_end_time
              - entity: input_datetime.calculator_duration
              - entity: input_number.calculator_kilowatt
                name: Forbrug kW
                icon: mdi:lightning-bolt
            title: Indstilling
      - type: vertical-stack
        cards:
          - type: markdown
            content: '#'
            title: Elpris i dag
          - type: custom:apexcharts-card
            experimental:
              color_threshold: true
            graph_span: 24h
            header:
              show: false
              show_states: true
              colorize_states: true
              standard_format: true
            span:
              start: day
            now:
              show: true
              label: Nu
            series:
              - entity: sensor.energi_data_service
                name: I dag
                type: column
                show:
                  extremas: true
                float_precision: 2
                data_generator: |
                  return (entity.attributes.raw_today.map((start, index) => {
                    return [new Date(start["hour"]).getTime(), entity.attributes.raw_today[index]["price"]];
                  }))
                color_threshold:
                  - value: 0
                    color: rgba(19, 120, 22, 0.8)
                  - value: 1
                    color: rgba(138, 177, 0, 0.92)
                    opacity: 1
                  - value: 2
                    color: rgba(198, 114, 0, 0.92)
                  - value: 3
                    color: rgba(200, 0, 0, 0.5)
                  - value: 4
                    color: rgba(140, 0, 72, 0.8)
                  - value: 5
                    color: darkred
            apex_config:
              yaxis:
                - title:
                    text: Dkk/kwh
                  decimalsInFloat: 2
              chart:
                height: 200px
          - type: markdown
            content: Er tilgængelig efter kl 13.00
            title: Elpris i morgen
          - type: custom:apexcharts-card
            experimental:
              color_threshold: true
            update_interval: 15min
            graph_span: 24h
            header:
              title: Electricity Price tomorrow
              show: false
            span:
              start: day
              offset: +1day
            series:
              - entity: sensor.energi_data_service
                name: I morgen
                type: column
                show:
                  extremas: true
                float_precision: 2
                data_generator: |
                  return (entity.attributes.raw_tomorrow.map((start, index) => {
                    return [new Date(start["hour"]).getTime(), entity.attributes.raw_tomorrow[index]["price"]];
                  })) 
                color_threshold:
                  - value: 0
                    color: rgba(19, 120, 22, 0.8)
                  - value: 1
                    color: rgba(138, 177, 0, 0.92)
                    opacity: 1
                  - value: 2
                    color: rgba(198, 114, 0, 0.92)
                  - value: 3
                    color: rgba(200, 0, 0, 0.5)
                  - value: 4
                    color: rgba(140, 0, 72, 0.8)
                  - value: 5
                    color: darkred
            apex_config:
              yaxis:
                - title:
                    text: Dkk/kwh
                  decimalsInFloat: 2
              chart:
                height: 200px
      - type: vertical-stack
        cards:
          - type: entities
            entities:
              - entity: switch.flush_1d_relay
          - type: logbook
            entities:
              - switch.flush_1d_relay
              - binary_sensor.price_calculator_is_cheapest
            hours_to_show: 120
      - type: entities
        entities:
          - button.node_2_ping

Bookmark the permalink.