#  - select:
#    - name: "Wohnzimmer Effekt"
#      unique_id: '6641823075755'
#      state: "{{ state_attr('light.wohnzimmer_hinten', 'effect') }}"
#      icon: mdi:firework
#      options: >
#        {{ state_attr('light.wohnzimmer_hinten', 'effect_list') }}
#      select_option:
#        - service: light.turn_on
#          target:
#            entity_id: light.wohnzimmer_hinten, light.wohnzimmer_vorne
#          data:
#            effect: "{{ option }}"
  - select:
    - name: "Wohnzimmer Palette"
      unique_id: '3107042775387'
      state: "{{ states('select.wohnzimmer_hinten_color_palette') }}"
      icon: mdi:palette
      options: >
        {{ state_attr('select.wohnzimmer_hinten_color_palette', 'options') }}
      select_option:
        - service: select.select_option
          target:
            entity_id: select.wohnzimmer_hinten_color_palette, select.wohnzimmer_vorne_color_palette
          data:
            option: '{{ option }}'
  - select:
    - name: "Available Media Players"
      unique_id: '6284128947660'
      state: "{{ states('input_text.selected_media_player') }}"
      options: >
        {{ states.media_player
        | rejectattr('state', 'in', ['off', 'idle', 'unavailable', 'unknown'])
        | map(attribute ='entity_id') | list }}
      select_option:
        - service: input_text.set_value
          target:
            entity_id: input_text.selected_media_player
          data:
            value: "{{ option }}"
  - sensor:
    - name: "power_other"
      unique_id: '5579422933393'
      unit_of_measurement: "W"
      icon: mdi:flash
      state: >
        {% set total = states('sensor.netzleistung') | float %}
        {% set solar = states('sensor.balkonkraftwerk_power') | float %}
        {% set raumduft = states('sensor.flur_raumduft_power') | float %}
        {% set keller = states('sensor.keller_power') | float %}
        {% set anrichte = states('sensor.kuche_anrichte_power') | float %}
        {% set musik = states('sensor.kuche_musik_power') | float %}
        {% set bett = states('sensor.schlafzimmer_bett_power') | float %}
        {% set heimkino_sz = states('sensor.schlafzimmer_heimkino_power') | float %}
        {% set deko = states('sensor.schreibtisch_deko_power') | float %}
        {% set schreibtisch = states('sensor.schreibtisch_power') | float %}
        {% set serverraum = states('sensor.serverraum_power') | float %}
        {% set heimkino_wz = states('sensor.wohnzimmer_heimkino_power') | float %}
        {% set spieleschrank = states('sensor.wohnzimmer_spieleschrank_power') | float %}
        {% set kuehlschrank = states('sensor.tz3000_ww6drja5_ts011f_leistung') | float %}
        {% set kaffeemaschine = states('sensor.kaffeemaschine_leistung_2') | float %}
        {% set waeschetrockner = states('sensor.waschetrockner_leistung') | float %}
        {% set waschmaschine = states('sensor.waschmaschine_leistung') | float %}
        {{ (total + solar - raumduft - keller - musik - bett - heimkino_sz - deko - schreibtisch - serverraum - heimkino_wz - spieleschrank - kuehlschrank - kaffeemaschine - waeschetrockner - waschmaschine) | round(1) }}
      device_class: power
      state_class: measurement
      attributes:
        last_reset: '1970-01-01T00:00:00+00:00'

# Shelly 3EM cumulative sensors (incl. PV)
  - sensor:
      # Template sensor for values of power import (active_power > 0)
      - name: power_import
        unique_id: '2385816278013'
        unit_of_measurement: 'W'
        state: >
          {% if (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) > 0 %}
            {{ (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float)|round(1) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        device_class: power
        state_class: measurement
        icon: mdi:transmission-tower-export
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

      # Template sensor for values of power export (active_power < 0)
      - name: power_export
        unique_id: '9143524256421'
        unit_of_measurement: 'W'
        state: >
          {% if (states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) < 0 %}
            {{ ((states('sensor.line_power_channel_a_power')|float + states('sensor.line_power_channel_b_power')|float + states('sensor.line_power_channel_c_power')|float) * -1 ) | round(1) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        device_class: power
        state_class: measurement
        icon: mdi:transmission-tower-import
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

      # Template sensor for values of power consumption
      - name: power_consumption
        unique_id: '3502047649408'
        unit_of_measurement: 'W'
        state: >
          {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.balkonkraftwerk_power')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.balkonkraftwerk_power')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ ((states('sensor.balkonkraftwerk_power')|float(0)) - states('sensor.power_export')|float(0)) | round(1) }}
          {% else %}
            {{ (states('sensor.power_import')|float(0) + states('sensor.balkonkraftwerk_power')|float(0)) | round(1) }}
          {% endif %}
        device_class: power
        state_class: measurement
        icon: mdi:home-lightning-bolt
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'

      # Internet Speed template sensor
      - name: internet_speed_in
        unique_id: '9519483670666'
        state: >
          {{ (( states('sensor.wan_in_derivative') | float * 8 / 1000000 ) | round(2)) }}
        unit_of_measurement: 'Mbps'
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'
      - name: internet_speed_out
        state: >
          {{ (( states('sensor.wan_out_derivative') | float * 8 / 1000000 ) | round(2)) }}
        unit_of_measurement: 'Mbps'
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'
