EPMatt / awesome-ha-blueprints

A curated collection of automation blueprints for Home Assistant.
https://epmatt.github.io/awesome-ha-blueprints
GNU General Public License v3.0
862 stars 254 forks source link

Bug - Failing first condition #367

Open summed opened 2 years ago

summed commented 2 years ago

Blueprint name

Controller - Philips 929002398602 Hue Dimmer switch v2 EPMatt/philips_929002398602.yaml

Home Assistant Core Version

2022.6.5

Home Assistant Installation Type

Home Assistant Container

Description

Condition is always false when using zigbee2mqtt.

  - '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'

If I tamper with this to make it resolve, the BP works fine. Otherwise always false.

Automation YAML config

- id: '1658107256440'                                                                                                                                                                                                                                                          
  alias: Controller - Philips 929002398602 Hue Dimmer switch v2                                                                                                                                                                                                                
  description: ''                                                                                                                                                                                                                                                              
  use_blueprint:                                                                                                                                                                                                                                                               
    path: EPMatt/philips_929002398602.yaml                                                                                                                                                                                                                                     
    input:                                                                                                                                                                                                                                                                     
      integration: Zigbee2MQTT                                                                                                                                                                                                                                                 
      controller_entity: sensor.0x001788XYZ_action                                                                                                                                                                                                                      
      helper_last_controller_event: input_text.text_hue_bp                                                                                                                                                                                                                     
      action_button_on_short:                                                                                                                                                                                                                                                  
      - service: light.toggle                                                                                                                                                                                                                                                  
        data: {}                                                                                                                                                                                                                                                               
        target:                                                                                                                                                                                                                                                                
          area_id: kitchen
condition:
  - condition: and
    conditions:
      # check that the button event is not empty
      - >-
        {%- set trigger_action -%}
        {%- if integration_id == "zigbee2mqtt" -%}
        {{ trigger.event.data.new_state.state }}
        {%- elif integration_id == "deconz" -%}
        {{ trigger.event.data.event }}
        {%- elif integration_id == "zha" -%}
        {{ trigger.event.data.command }}
        {%- endif -%}
        {%- endset -%}
        {{ trigger_action not in ["","None"] }}
      # only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
      # this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
      - '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Trigger the automation '....'
  4. See error

Expected behavior

That the trigger fires and the bp works with zigbee2mqtt

Actual Behaviour

always stops with a false condition

Additional Details

Screenshots

No response

Additional context

No response

kahancock commented 2 years ago

Just starting trying to use this blueprint and can confirm same behavior.

EPMatt commented 2 years ago

⚠️ Important announcement about the project: #371 ⚠️

I'd like to kindly ask for your feedback about our work here. If you have time, please answer the poll in the above discussion. This will help shaping the future of Awesome HA Blueprints. 🚀

Thank you!

EPMatt commented 2 years ago

Hi @summed @kahancock, thank you for reporting here.

Can you please share the name of the blueprint you're experiencing issues with? Furthermore, can you please provide the full YAML configuration for the automation? I'm afraid it would be hard to solve your issue without having such information.

Moreover, I noticed that you're using Zigbee2MQTT. Please note that we're using legacy Home Assistant triggers to detect button clicks for Z2M (docs). Our blueprints currently do not support device triggers. Please make sure you've the legacy_triggers option set to true (default value) in the Z2M configuration for controller blueprints to work.

Thanks!

summed commented 2 years ago

@EPMatt Hi Matteo, sorry for the missinformation. I have update the ticket a bit. The bp seems to be working without issue atm, when I have changed the condition a bit.

- condition: and
  conditions:
  - '{%- set trigger_action -%} {%- if integration_id == "zigbee2mqtt" -%} {{ trigger.event.data.new_state.state
    }} {%- elif integration_id == "deconz" -%} {{ trigger.event.data.event }} {%-
    elif integration_id == "zha" -%} {{ trigger.event.data.command }} {%- endif -%}
    {%- endset -%} {{ trigger_action not in ["","None"] }}'
  - '{{ integration != "Zigbee2MQTT" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'

While I know programming, I am a complete beginner to the homeassistant bp DSL. Might there be some issue with variable scoping where the original integration_id is unset?

haffi78 commented 2 years ago

What is it that you changed to get this to work , when I install this blueprint, it detects the button but then does nothing, cause of Failing the first condition, and how do I fix it ? I see you changed maybee Zigbee2MQTT from none caps ?