Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

иногда значания недоступны #13

Open
532910 opened this issue Jul 25, 2024 · 3 comments
Open

иногда значания недоступны #13

532910 opened this issue Jul 25, 2024 · 3 comments

Comments

@532910
Copy link

532910 commented Jul 25, 2024

я использую следующий скрипт и он иногда фэйлится:

Error: In 'template' condition: ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states('input_text.electricity_night')|int >= (states('sensor.pesc_electricity_night')|int -1) and states('input_text.electricity_night')|int <= (states('sensor.pesc_electricity_night')|int +100) }}' but no default was specified

sequence:
  - alias: electricity day
    if:
      - condition: template
        value_template: >-
          {{ states('input_text.electricity_day')|int >=
          (states('sensor.pesc_electricity_day')|int -1) and
          states('input_text.electricity_day')|int <=
          (states('sensor.pesc_electricity_day')|int +200) }}
    then:
      - service: pesc.update_value
        target:
          entity_id: sensor.pesc_electricity_day
        data:
          value: "{{ states( 'input_text.electricity_day' ) | int }}"
  - alias: electricity night
    if:
      - condition: template
        value_template: >-
          {{ states('input_text.electricity_night')|int >=
          (states('sensor.pesc_electricity_night')|int -1) and
          states('input_text.electricity_night')|int <=
          (states('sensor.pesc_electricity_night')|int +100) }}
    then:
      - service: pesc.update_value
        target:
          entity_id: sensor.pesc_electricity_night
        data:
          value: "{{ states( 'input_text.electricity_night' ) | int }}"
  - alias: water cold
    if:
      - condition: template
        value_template: >-
          {{ states('input_text.water_cold')|int >=
          (states('sensor.pesc_water_cold')|int -1) and
          states('input_text.water_cold')|int <=
          (states('sensor.pesc_water_cold')|int +5) }}
    then:
      - service: pesc.update_value
        target:
          entity_id: sensor.pesc_water_cold
        data:
          value: "{{ states( 'input_text.water_cold' ) | int }}"
  - alias: water hot
    if:
      - condition: template
        value_template: >-
          {{ states('input_text.water_hot')|int >=
          (states('sensor.pesc_water_hot')|int -1) and
          states('input_text.water_hot')|int <=
          (states('sensor.pesc_water_hot')|int +5) }}
    then:
      - service: pesc.update_value
        target:
          entity_id: sensor.pesc_water_hot
        data:
          value: "{{ states('input_text.water_hot')|int }}"

первый блок отрабатывает всегда, а вот последующие иногда фэйлятся

дело точно не в input_text.*

думаю если вставить задержку между блоками будет работать стабильнее

вобще хотелось бы все показания одной транзакцией отправлять

@532910
Copy link
Author

532910 commented Jul 25, 2024

добавил wait_template посмотрю как будет работать

sequence:
  - alias: electricity day
    sequence:
      - wait_template: "{{ has_value('sensor.pesc_electricity_day') }}"
      - if:
          - condition: template
            value_template: >-
              {{ states('input_text.electricity_day')|int >=
              (states('sensor.pesc_electricity_day')|int -1) and
              states('input_text.electricity_day')|int <=
              (states('sensor.pesc_electricity_day')|int +200) }}
        then:
          - service: pesc.update_value
            target:
              entity_id: sensor.pesc_electricity_day
            data:
              value: "{{ states( 'input_text.electricity_day' ) | int }}"
  - alias: electricity night
    sequence:
      - wait_template: "{{ has_value('sensor.pesc_electricity_night') }}"
      - if:
          - condition: template
            value_template: >-
              {{ states('input_text.electricity_night')|int >=
              (states('sensor.pesc_electricity_night')|int -1) and
              states('input_text.electricity_night')|int <=
              (states('sensor.pesc_electricity_night')|int +100) }}
        then:
          - service: pesc.update_value
            target:
              entity_id: sensor.pesc_electricity_night
            data:
              value: "{{ states( 'input_text.electricity_night' ) | int }}"
  - alias: water cold
    sequence:
      - wait_template: "{{ has_value('sensor.pesc_water_cold') }}"
      - if:
          - condition: template
            value_template: >-
              {{ states('input_text.water_cold')|int >=
              (states('sensor.pesc_water_cold')|int -1) and
              states('input_text.water_cold')|int <=
              (states('sensor.pesc_water_cold')|int +5) }}
        then:
          - service: pesc.update_value
            target:
              entity_id: sensor.pesc_water_cold
            data:
              value: "{{ states( 'input_text.water_cold' ) | int }}"
  - alias: water hot
    sequence:
      - wait_template: "{{ has_value('sensor.pesc_water_hot') }}"
      - if:
          - condition: template
            value_template: >-
              {{ states('input_text.water_hot')|int >=
              (states('sensor.pesc_water_hot')|int -1) and
              states('input_text.water_hot')|int <=
              (states('sensor.pesc_water_hot')|int +5) }}
        then:
          - service: pesc.update_value
            target:
              entity_id: sensor.pesc_water_hot
            data:
              value: "{{ states('input_text.water_hot')|int }}"

@dentra
Copy link
Owner

dentra commented Jul 25, 2024

вобще хотелось бы все показания одной транзакцией отправлять

в мастере

@dentra
Copy link
Owner

dentra commented Jul 26, 2024

по поводу того что возможно иногда некоторые сенсоры недоступны, wait_template может "повесить" скрипт на очень долго, возможно стоит использовать обычный template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants