ChatGPT4-made garage gate sensor yaml

Hi all,

I have a garage gate switch, and two zigbee contact sensors sticked on my garage gate.
Been trying to wrap my head around this sensor and garage cover. Read and reread all the posts on this topic.
Not really good in yaml, so i tried my luck with ChatGPT :slight_smile:

template:
  - trigger:
      - platform: state
        entity_id:
          - binary_sensor.0x00124b00293323b0_contact
          - binary_sensor.0x00124b002933478e_contact
          - switch.0xa4c1388a335561b8
    binary_sensor:
      - name: "Garažo Vartų Būklė"
        state: >-
          {% if is_state('binary_sensor.0x00124b00293323b0_contact', 'on') and is_state('binary_sensor.0x00124b002933478e_contact', 'off') %}
            atidaryta
          {% elif is_state('binary_sensor.0x00124b00293323b0_contact', 'off') and is_state('binary_sensor.0x00124b002933478e_contact', 'on') %}
            uždaryta
          {% elif is_state('switch.0xa4c1388a335561b8', 'on') %}
            atidaroma
          {% elif is_state('switch.0xa4c1388a335561b8', 'off') and not is_state('binary_sensor.0x00124b00293323b0_contact', 'on') and not is_state('binary_sensor.0x00124b002933478e_contact', 'on') %}
            uždaroma
          {% else %}
            užstrigę
          {% endif %}
        device_class: garage_door

switch:
  - platform: template
    switches:
      garage_door_control:
        value_template: "{{ is_state('switch.0xa4c1388a335561b8', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.0xa4c1388a335561b8
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.0xa4c1388a335561b8

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garažo Vartai"
        value_template: >-
          {% if is_state('binary_sensor.0x00124b00293323b0_contact', 'on') %}
            open
          {% elif is_state('binary_sensor.0x00124b002933478e_contact', 'on') %}
            closed
          {% elif is_state('switch.0xa4c1388a335561b8', 'on') %}
            opening
          {% elif not is_state('binary_sensor.0x00124b00293323b0_contact', 'on') and not is_state('binary_sensor.0x00124b002933478e_contact', 'on') %}
            closing
          {% else %}
            jammed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.0xa4c1388a335561b8
        close_cover:
          service: switch.turn_on
          data:
            entity_id: switch.0xa4c1388a335561b8
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: switch.0xa4c1388a335561b8
        icon_template: >-
          {% if is_state('binary_sensor.0x00124b00293323b0_contact', 'on') %}
            mdi:garage-open
          {% elif is_state('binary_sensor.0x00124b002933478e_contact', 'on') %}
            mdi:garage
          {% elif is_state('switch.0xa4c1388a335561b8', 'on') %}
            mdi:arrow-up-down
          {% else %}
            mdi:garage-alert
          {% endif %}

Still no luck, it kinda works, but the icons do not change, and it always says it is “open”.

Could there be a mistake in the code?

Thank you for your insights,

Paul

Good luck debugging this.

OK thanks for the answer, i didn’t know that AI wasn’t allowed.

So how can i create this sensor without any yaml knowledge? Been struggling with this for the last 6 months, reading all the posts, and trying different code variations… This one seems closest to the final code than ever :slight_smile:

Reading the documentation, having a go and asking here for help is the preferred method.

2 Likes

Could you explain what you are trying to achieve? Looks like maybe you want to open the garage door when the contact sensors show the gate has opened.

For something like that you need an automation. Edit it in the UI and use entity states, not devices.

I agree that AI answers aren’t often helpful, and don’t belong here as responses to posts. But in this case, the (presumably human) poster just has some partially-working YAML and is looking for help fine-tuning it. To me, it doesn’t really matter where that code was copied and pasted from, be it an AI bot or just some example they found somewhere.

In fact, I personally would have no problem with the OP re-posting the exact same question, without mentioning where the failing code came from.

2 Likes

A binary state has 2 (useful) states, ‘on’ and ‘off’ (not counting unknown and unavailable)

I guess these are contact sensors for open and closed ?

The problem with that is that GPT often hallucinates things that look reasonable that a human would never make up. Like this:

That one was easy to spot, others less so. Takes longer to “fine-tune” the idiot robot sick than to write from scratch. Look at that garbage about setting various states on a binary sensor.

Yes, these are the top and bottom zigbee contact sensors. Idealy, i woukd like it to display 5 states (closed, open, opening, closing, jammed), but what i have now is 4 states, which is fine! (open,closed,moving,jammed).

The problem is that the state displays it is always open, andbthe icons are not changing. If it is always open, then the “close” arrow is visible only. The “open” arrow is grayed out.

i want to have a garage cover template, that woukd display 5 states (opening, closing,open,closed,jammed), to have three separate buttons (it kinda works - mushroom cover card shows me those), ant to have the icons change based on state.

Are you certain the 23b0 sensor is working?

Not the same thing: using AI to answer a question versus answering why AI got it wrong. Were you a hall monitor in school?

1 Like

They did work, however i had some zigbee connectivity issues, and low LQI.

Out of house right now, i will check tomorrow thank you!

Yup, those two sensors are disconnected.

Will start from debugging the z2m poor signal…

Thanks anyway