Stworzenie wentylatora przy użyciu dwóch przekaźników

Czołem!

Pytałem już o to 2 tygodnie temu na forum HA ale brak odpowiedzi. Liczę, że tutaj ktoś pomoże.

Mam wentylator 2 biegowy, który kontroluję dwoma przekaźnikami.
Wentylator jest wyłączony gdy switch.l1==off i switch.l2==off
Wentylator jest na pierwszym biegu gdy switch.l1==on i switch.l2==off
Wentylator jest na drugim biegu gdy switch.l1==off i switch.l2==on
Włączenie odpowiedniego biegu lub wyłączenie kontroluję przez 3 skrypty:
script.closet_fan_off
script.closet_fan_low
script.closet_fan_high

Chciałbym teraz stworzyć w HA wentylator. Tak żeby móc na dashboard wyświetlić kartę wentylatora, na której będą wyświetlone 3 guziki: off, low, high. Nie potrafię tego ogarnąć, na tę chwilę mam:

fan:
   - platform: template
     fans:
       tv_fan:
         friendly_name: TV Fan
         entity_id: fan.tv
         preset_mode_template: >
           {% if is_state('switch.l1', 'off') and is_state('switch.l2', 'off') %}
             off
           {% elif is_state('switch.l1', 'on') and is_state('switch.l2', 'off') %}
             low
           {% elif is_state('switch.l1', 'off') and is_state('switch.l2', 'on') %}
             high
           {%else %}
             off
           {% endif %}
         turn_on:
           - service: switch.turn_on
             entity_id: switch.l1
         turn_off:
           - service: switch.turn_off
             entity_id: switch.l1
           - service: switch.turn_off
             entity_id: switch.l2

Niestety w HA pojawia mi się wentylator o 2 guzikach więc coś tu jest nie tak.

Rozwiązania nie podam ale coś mi się w Twojej konfiguracji nie podoba:
Budujesz warunkową listę presetów

         preset_mode_template: >
           {% if is_state('switch.l1', 'off') and is_state('switch.l2', 'off') %}
             off
           {% elif is_state('switch.l1', 'on') and is_state('switch.l2', 'off') %}
             low
           {% elif is_state('switch.l1', 'off') and is_state('switch.l2', 'on') %}
             high
           {%else %}
             off
           {% endif %}

W zależności od stanu przekaźników będą tylko wybrane nastawy.
Dlaczego dwa? - powinien być jeden :slight_smile:
Wg. dokumentacji lista dostępnych presetów jest budowana w sposób

.....
        preset_mode_template: "{{ states('input_select.preset_mode') }}"
        preset_modes:
          - 'off'
          - 'high'
          - 'low'
......

O ile co do pierwszej części mogę się mylić, to preset_modes bym jednak dodał

W ogóle tego nie widać w załączonej konfiguracji?

To Twój post: Two relays and a template fan - Configuration - Home Assistant Community
Poczytaj Fan template with 2 relays - Configuration - Home Assistant Community

Dzięki za zainteresowanie! Tak, to mój post. Przerobiłem kod z powyższego linku tak:

input_boolean:
  office_fan:
    name: Office Fan Power

input_text:
  office_fan:
    name: Office Fan Speed

fan:
  - platform: template
    fans:
      office_fan:
        value_template: "{{states('input_boolean.office_fan')}}"
        speed_template: "{{states('input_text.office_fan')}}"
        turn_on:
          - service: input_text.set_value
            data:
              entity_id: input_text.office_fan
              value: 'low'
          - service: homeassistant.turn_on
            entity_id: switch.4ch_switch_szafka_tv_l1, input_boolean.office_fan
        turn_off:
          - service: homeassistant.turn_off
            entity_id: switch.4ch_switch_szafka_tv_l1, switch.4ch_switch_szafka_tv_l2, input_boolean.office_fan
        set_speed:
          - service_template: "switch.turn_{{'on' if speed in ['low'] else 'off'}}"
            entity_id: switch.4ch_switch_szafka_tv_l1
          - service_template: "switch.turn_{{'on' if speed in ['high'] else 'off'}}"
            entity_id: switch.4ch_switch_szafka_tv_l2
          - service: input_text.set_value
            data_template:
              entity_id: input_text.office_fan
              value: '{{speed}}'

Jak klikam SPRAWDŹ KONFIGURACJĘ to dostaję:

Ostrzeżenia konfiguracji
Invalid config for 'template' from integration 'fan' at configuration.yaml, line 63: 'speed_template' is an invalid option for 'fan.template', check: fans->office_fan->speed_template
Invalid config for 'template' from integration 'fan' at configuration.yaml, line 74: 'set_speed' is an invalid option for 'fan.template', check: fans->office_fan->set_speed

Następnie skopiowałem kolejny konfig:

fan:
  - platform: template
    fans:
      stove_fan:
        friendly_name: "Stove Fan"
        value_template: >
          {%- if states.switch.stove_fan_relay_low.state == 'on' or states.switch.stove_fan_relay_high.state == 'on' -%} on 
          {%- else -%} off
          {%- endif %}
          
        percentage_template: >
          {%- if states.switch.stove_fan_relay_low.state == 'on' -%} 50 
          {%- elif states.switch.stove_fan_relay_high.state == 'on' -%} 100
          {%- else -%} 0
          {%- endif %}

        turn_on:
          service: homeassistant.turn_on
          entity_id: switch.stove_fan_relay_low
        turn_off:
          service: homeassistant.turn_off
          entity_id: switch.stove_fan_relay_low, switch.stove_fan_relay_high
        set_percentage:
          - service_template: >-
                {%- if (percentage > 0) and (percentage <=50) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.stove_fan_relay_low
          - service_template: >
                {%- if (percentage > 50) and (percentage <=100) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.stove_fan_relay_high
        speed_count: 2

Nie mam u siebie stove_fan_relay_low oraz stove_fan_relay_high ale mimo to sprawdzenie konfiguracji przechodzi pomyślnie. Zmieniam więc pierwsze wystąpienie states.switch.stove_fan_relay_low.state na states.switch.4ch_switch_szafka_tv_l1.state

i sprawdzając konfigurację dostaję:

Ostrzeżenia konfiguracji
Invalid config for 'template' from integration 'fan' at configuration.yaml, line 87: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'ch_switch_szafka_tv_l1') for dictionary value 'fans->stove_fan->value_template', got "{%- if states.switch.4ch_switch_szafka_tv_l1.state == 'on' or states.switch.stove_fan_relay_high.state == 'on' -%} on  {%- else -%} off {%- endif %}\n"

Nie rozumiem tego błędu.

EDIT:
Zacząłem kombinować ze składnią i dałem tak:
states.switch['4ch_switch_szafka_tv_l1'].state
no i zaczęło działać! Ślicznie dziękuję!!!

To ślicznie proszę o przedstawienie końcowej działającej konfiguracji dla potomnych :slight_smile: .

Oczywiście. Poniżej cała konfiguracja z pliku configuration.yaml:

fan:
  - platform: template
    fans:
      closet_fan:
        friendly_name: "Closet Fan"
        value_template: >
          {%- if states.switch['4ch_switch_szafka_tv_l1'].state == 'on' or states.switch['4ch_switch_szafka_tv_l2'].state == 'on' -%} on 
          {%- else -%} off
          {%- endif %}
        percentage_template: >
          {%- if states.switch['4ch_switch_szafka_tv_l1'].state == 'on' -%} 50 
          {%- elif states.switch['4ch_switch_szafka_tv_l2'].state == 'on' -%} 100
          {%- else -%} 0
          {%- endif %}
        turn_on:
          service: homeassistant.turn_on
          entity_id: switch.4ch_switch_szafka_tv_l1
        turn_off:
          service: homeassistant.turn_off
          entity_id: switch.4ch_switch_szafka_tv_l1, switch.4ch_switch_szafka_tv_l2
        set_percentage:
          - service_template: >-
                {%- if (percentage > 0) and (percentage <=50) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.4ch_switch_szafka_tv_l1
          - service_template: >
                {%- if (percentage > 50) and (percentage <=100) -%} homeassistant.turn_on 
                {%- else -%} homeassistant.turn_off
                {%- endif %}
            entity_id: switch.4ch_switch_szafka_tv_l2
        speed_count: 2

Te 3 skrypty o których pisałem były użyte wyłącznie w Node-RED. Stwierdziłem, że je skasuję i podepnę się bezpośrednio pod switch’e:

[{"id":"64f6d396584d731b","type":"server-state-changed","z":"60dab39828029ce9","name":"szafka tv - temperatura","server":"89fbae45.759a4","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"sensor.szafka_pod_tv_temperature","entityIdType":"exact","outputInitially":false,"stateType":"num","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":520,"y":1520,"wires":[["5e992b109e8f10fc"]]},{"id":"5e992b109e8f10fc","type":"switch","z":"60dab39828029ce9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"28","vt":"num"},{"t":"btwn","v":"28","vt":"num","v2":"34","v2t":"num"},{"t":"gte","v":"34","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":710,"y":1520,"wires":[["5676a188db51c7f8"],["814c274031fc8265","d0fadb18bb92087e"],["5023448066ca83f0","a9ee37788c706803"]]},{"id":"5676a188db51c7f8","type":"api-call-service","z":"60dab39828029ce9","name":"wyłączony","server":"89fbae45.759a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.4ch_switch_szafka_tv_l1","switch.4ch_switch_szafka_tv_l2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1460,"wires":[[]]},{"id":"814c274031fc8265","type":"api-call-service","z":"60dab39828029ce9","name":"low - L1 ON","server":"89fbae45.759a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.4ch_switch_szafka_tv_l1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1500,"wires":[[]]},{"id":"d0fadb18bb92087e","type":"api-call-service","z":"60dab39828029ce9","name":"low - L2 OFF","server":"89fbae45.759a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.4ch_switch_szafka_tv_l2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1540,"wires":[[]]},{"id":"5023448066ca83f0","type":"api-call-service","z":"60dab39828029ce9","name":"high - L1 OFF","server":"89fbae45.759a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.4ch_switch_szafka_tv_l1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":1580,"wires":[[]]},{"id":"a9ee37788c706803","type":"api-call-service","z":"60dab39828029ce9","name":"high - L2 ON","server":"89fbae45.759a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.4ch_switch_szafka_tv_l2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1620,"wires":[[]]},{"id":"89fbae45.759a4","type":"server","name":"Home Assistant","addon":true}]

No i efekt końcowy na którym mi zależało czyli jedno urządzenie, widoczne jako wentylator:

1 Like