Writing YAML with AI - OpenGPT

Hi folks!

Sorry if this is somewhere else, I couldn’t find it and I’m new. Just posting this for anyone like me who’s new to home assistant and could do with a helping hand! OpenGPT really helps with writing code and explains it to so you can learn. Was pretty blown away

In the last example, it should be a Time Condition. A “weekday” condition doesn’t exist in Home Assistant; ChatGPT’s suggested example won’t pass configuration check.

So what’s its response if you tell it that it made a mistake?

1 Like

Interestingly it took me a fair few goes to try and replicate it, as it spits out different codes. It gave me not_away instead of home, and tried to do the days differently, but still incorrectly I guess.

This time it gave me this:

livingroom_lights:

  • trigger:
    platform: time
    before: ‘sunset’
    offset: ‘-01:00:00’
    days:
    - mon
    - wed
    - thu
    - sat
    - sun
  • condition:
    platform: state
    entity_id: person.martin
    state: ‘not_away’
  • action:
    service: light.turn_on
    entity_id: light.livingroom_lights

that doesn’t work

I apologize if the previous code did not work for you. It is difficult for me to say what may have gone wrong without knowing more about your specific setup. YAML code can be finicky, so it’s possible that there was a syntax error or other issue with the code.

If you are having trouble with the YAML code, it may be helpful to try using a linting tool to check for any syntax errors or other issues. You can also try breaking down the code into smaller chunks and testing each piece separately to see where the problem may be occurring.

If you continue to have trouble, you may want to consider asking for help on a forum or community platform where other users may be able to provide more specific guidance based on your situation.

try the days of the week code differently

livingroom_lights:

  • trigger:
    platform: time
    before: ‘sunset’
    offset: ‘-01:00:00’
    days: ‘mon-sun’
    exclude:
    - tue
    - fri
  • condition:
    platform: state
    entity_id: person.martin
    state: ‘not_away’
  • action:
    service: light.turn_on
    entity_id: light.livingroom_lights

try again with a condition platform

livingroom_lights:

  • trigger:
    platform: time
    before: ‘sunset’
    offset: ‘-01:00:00’
  • condition:
    platform: time
    weekday:
    - mon
    - wed
    - thu
    - sat
    - sun
  • condition:
    platform: state
    entity_id: person.martin
    state: ‘not_away’
  • action:
    service: light.turn_on
    entity_id: light.livingroom_lights

Not the best person to be evaluating this as I don’t know how to code haha. Just thought it was interesting.

It seems to have potential but, in its current form, a tutor that provides incorrect examples isn’t the best guide for new users.

If you continue to have trouble, you may want to consider asking for help on a forum or community platform where other users may be able to provide more specific guidance based on your situation.

That’s good advice. :slightly_smiling_face:

1 Like

FYI