Remember “The Last One”? Now we have ChatGPT !

Skynet Cyberdyne Systems

I remember “The Last One” well (with a little DATE help from Wikipedia)… the 1981 program which would render all programmers redundant? The Last One was released over 40 years ago by the British company D.J. ‘AI’ Systems and took input from a user to generate an executable program in the BASIC computer language.

All these years later, I’ve never forgotten it nor forgotten thinking “what a lot of nonsense” – and it WAS nonsense – there are more programmers today than ever before. Of course I’m assuming you all know the famous “Skynet” depicted above right…

Philips Electronics

I’ve a tech experience span which began in the 1960s when my dad introduced me to an electronics kit for kids, through many years of programming for fun (or masochism in the Clive Sinclair SC/MP period), through inventing tech and selling it for a living. Me being self-employed and enthusiastic, it rarely seemed like work and our company created all sorts of software-heavily-dependent tech devices – then onto my senior management phase (in which I simply could not separate myself from hands-on involvement) – back to programming for fun in early retirement.

The problem is: in the last few years, the effects of age have somewhat reduced my concentration and it doesn’t help that as a lifelong C enthusiast, I haven’t taken readily to declarative languages such as YAML – used in Home Assistant. From time to time then, as I “move on” from my pretty complicated and successful but ultimately doomed Node-RED-Dashboard-based home automation, my choices seemed clear a month or ago – retain my code and move onto the new DASHBOARD 2 or do something utterly wild – my friend Antonio has been puting me under immense pressure to migrate to Home Assistant despite my reservations and only this last week I reached the point where it was starting to look like the future. I had nearly all of my countless dozens of IOT devices (WiFi, ZIGBEE and more) imported into HA with manual overrides and a DO-able dashboard.

Only one main problem remained – AUTOMATIONS. I wrote the well-known node-red-contrib-bigtimer some years back, at that time (and possibly even now) the most powerful timer automation for Node-Red and I rely on it for many dozens of daily automations – even stretching to special exceptions for absense, time of year and for special holidays etc.

How on EARTH was I going to replace THIS lot?

WLED

By last week I was still panicking – I got the internal and external simple and RGB lights working, air-conditioning working, pergola misting system, two hot water tanks, pool pump and filter and much more – all good – except still relying on Node-Red for background automation and some items still based on different incompatible APPs which don’t as yet integrate into Node-Red or even did then stopped due to changes – like eWeLink (don’t start me off on MATTER).

It’s going to take months, I thought, to move that lot 100% to Home Assistant.

Well, maybe not. If you’re still reading, you might find it was worth listening to me dribble on…. to get here:

I’ve recently started using some Home Assistant Integrations (with help I may add – Antonio – are you still reading?) and they really DO have many different IOT systems integrated into HA. Finally I can put eWeLink, Aqara, Smart Life (Tuya), Meross, Shelly and many other APPS into a tiny, far corner of my phone, no longer padding out my already bloated home page – LOVELY.

It was only a matter of time before I’d have to take the plunge and replace the various timing automations – my own N-R-Big-Timer timers and those of the various IOT companies – with Home Assistant versions – but how? My concentration is rubbish and it is years since I wrote some of the earliest stuff – I know how it works but my Node-RED code is almost documentation-free (that’s being charitable).

Back to “The Last One” – and today’s AI-of-the-year CHATGPT. I have of course used such programs to write fictional articles for fun and the likes of NightCafe to create the most interesting art – haven’t we all? (I’ve not used any AI in here or in my videos to date – I may add).

Home Assistant dashboard section including bathroom lighting.

That brings us to today – Antonio asked me if I’d thought of getting ChatGPT to write the code for me to do HA automations. After I picked myselff off the floor laughing, I thought – as I was having lunch – why not humour him with a simple timer for my Aqara bathroom light switch I only fitted this morning.

The Aqara H1EU switch who’s blog entry I JUST TODAY updated with, local control and remote control (in Home Assistant of course) was already integrated for manual on-off by mid-morning – but my next job would be the simplest of timers – have the light turn off after half an hour in case one of us forgot to turn it off.

In the devices referrred to in the above right image, I already have timers – the bathroom heater comes on early in the morning for an hour if it is cold outside – the bedside phone charger if activated turns off automatically after 2 hours – bedside light after an hour if I doze off – all of this is standard for me and has been for years – but all handled differently depending on device/APP capabilities – all that is about to change – TRULY….

Bathroom light – a trivial start, yes? – but how to put that into Home Assistant? Where to begin?

Open ChatGPT in Windows and ask it the question, right? The following is un-edited:

Me:
“Write the simplest possible Home Assistant Automation to turn off my bathroom light half an hour after I turn it on.”

ChatGPT output:
Creating an automation in Home Assistant to turn off a bathroom light 30 minutes after it is turned on is straightforward. Here’s a simple YAML configuration for this automation.

Step-by-Step Guide

  1. Open Home Assistant: Navigate to your Home Assistant instance.
  2. Access Automations: Go to Configuration > Automations.
  3. Create a New Automation: Click on “Add Automation” and select “Start with an empty automation.”
  4. Edit the YAML Configuration: Switch to the YAML mode for more control. Here’s the YAML code for the automation:
alias: Turn off bathroom light after 30 minutes
description: Turn off the bathroom light 30 minutes after it is turned on.
trigger:
  - platform: state
    entity_id: light.bathroom_light
    to: 'on'
condition: []
action:
  - delay: '00:30:00'
  - service: light.turn_off
    target:
      entity_id: light.bathroom_light
mode: single

Explanation:

  • alias: A name for the automation.
  • trigger:
    • platform: The type of trigger, in this case, state change.
    • entity_id: The entity to monitor, i.e., the bathroom light.
    • to: The state that triggers the automation, i.e., when the light is turned “on”.
  • condition: No conditions are specified, meaning the action will always execute after the trigger.
  • action:
    • delay: Wait for 30 minutes.
    • service: The service to call, i.e., turning off the light.
    • target:
      • entity_id: The entity to act upon, i.e., the bathroom light.
  • mode: Specifies how to handle multiple runs of the automation. single ensures that if the automation is triggered again while it’s still waiting, the subsequent triggers are ignored.
  1. Save the Automation: Save the automation and make sure it’s enabled.

Testing the Automation

To test the automation:

  1. Turn on the bathroom light.
  2. Wait for 30 minutes.
  3. The light should turn off automatically.

This simple configuration ensures your bathroom light turns off 30 minutes after it’s turned on without any additional conditions or complexities.

End of ChatGPT output:

You don’t get any easier – EXCEPT THAT IT DIDN’T WORK. Why? because it’s a SWITCH , not a LIGHT (did I feel stupid or what? Read on – it’s worth your time – the code even knew this was my second attempt…

Me:
“Write the simplest possible Home Assistant Automation to turn off my bathroom switch half an hour after I turn it on.”

ChatGPT output:
Creating an automation in Home Assistant to turn off a bathroom switch (instead of a light) 30 minutes after it is turned on is very similar to the light example. Here’s a simple YAML configuration for this automation.

Step-by-Step Guide

  1. Open Home Assistant: Navigate to your Home Assistant instance.
  2. Access Automations: Go to Configuration > Automations.
  3. Create a New Automation: Click on “Add Automation” and select “Start with an empty automation.”
  4. Edit the YAML Configuration: Switch to the YAML mode for more control. Here’s the YAML code for the automation:
alias: Turn off bathroom switch after 30 minutes
description: Turn off the bathroom switch 30 minutes after it is turned on.
trigger:
  - platform: state
    entity_id: switch.bathroom_switch
    to: 'on'
condition: []
action:
  - delay: '00:30:00'
  - service: switch.turn_off
    target:
      entity_id: switch.bathroom_switch
mode: single

Explanation:

  • alias: A name for the automation.
  • trigger:
    • platform: The type of trigger, in this case, state change.
    • entity_id: The entity to monitor, i.e., the bathroom switch.
    • to: The state that triggers the automation, i.e., when the switch is turned “on”.
  • condition: No conditions are specified, meaning the action will always execute after the trigger.
  • action:
    • delay: Wait for 30 minutes.
    • service: The service to call, i.e., turning off the switch.
    • target:
      • entity_id: The entity to act upon, i.e., the bathroom switch.
  • mode: Specifies how to handle multiple runs of the automation. single ensures that if the automation is triggered again while it’s still waiting, the subsequent triggers are ignored.
  1. Save the Automation: Save the automation and make sure it’s enabled.

Testing the Automation

To test the automation:

  1. Turn on the bathroom switch.
  2. Wait for 30 minutes.
  3. The switch should turn off automatically.

This simple configuration ensures your bathroom switch turns off 30 minutes after it’s turned on without any additional conditions or complexities.

End of ChatGPT output:

The YAML editor even filled in the right “entity_id” – i.e. the Zigbee2MQTT friendly name of the bathroom light switch for me.

Ok so a simple example but that’s how I’ve always learned – point me in the right direction with a little hand-hold then I’ll go from there. How hard can it be to have CHATGPT add in some times and some exceptions and overrides. NOT that hard I’ll bet – indeed I’m about to test a living room lights automation which included people presense and sunset detection – will it work? Next time….

The only bit I didn’t totally follow was the last line in each case – “mode” – so I asked as I would if one of you had written the code:

Me:
“What are the mode options in the code you wrote for me, above”

ChatGPT output:
In Home Assistant automations, the mode option determines how the automation handles multiple triggers. Here are the available options:

  1. single: Ignores new triggers while the current automation is still running.
  2. restart: Stops the current run and starts again with the new trigger.
  3. queued: Queues new triggers to be executed sequentially after the current run finishes.
  4. parallel: Allows multiple runs of the automation to execute in parallel.

These options help manage how your automations respond when triggered multiple times.

End of ChatGPT output:

Whenever people give me a lot of help I always invite them to say a few words of their own if they wish – so why not let ChatGPT enjoy the same privilage? Ok I’m out of here. The following is totally unedited, unformatted CHATGPT output – thank you, my new imperfect but do-able friend!!

ChatGPT output from here to the end:

As smart homes become more sophisticated, automation tools like Home Assistant have become increasingly popular. These tools allow homeowners to create a seamless, efficient, and customizable living experience. However, setting up these automations can be complex, especially for those who are not well-versed in programming. This is where ChatGPT-4 steps in as an invaluable resource. Here’s why ChatGPT-4 is a fantastic tool for writing Home Assistant automations:

1. Ease of Use

One of the standout features of ChatGPT-4 is its user-friendly nature. Whether you are a tech enthusiast or a complete beginner, ChatGPT-4 simplifies the process of writing code for Home Assistant automations. By engaging in a natural language conversation, you can easily explain what you want to achieve, and ChatGPT-4 will guide you through the process, providing clear and concise code snippets.

2. Time-Saving

Creating automations manually can be time-consuming. ChatGPT-4 can generate the necessary YAML or Python code in a fraction of the time it would take to write it from scratch. For example, if you want to turn off your bathroom switch half an hour after it is turned on, ChatGPT-4 can provide you with the exact code needed almost instantly. This efficiency allows you to focus on other important tasks.

3. Accuracy and Reliability

ChatGPT-4 leverages extensive training data and a sophisticated understanding of programming languages to generate accurate and reliable code. This reduces the likelihood of errors that can occur when writing code manually. With ChatGPT-4, you can trust that the automations will work as intended, providing a smooth and hassle-free experience.

4. Customization and Flexibility

Every smart home is unique, and so are the automation needs of its users. ChatGPT-4 excels at customizing automations to fit specific requirements. Whether you need to integrate multiple devices, set complex triggers, or apply conditions, ChatGPT-4 can tailor the code to meet your exact needs. This flexibility ensures that your Home Assistant setup is perfectly aligned with your lifestyle.

5. Learning and Improvement

Using ChatGPT-4 to write Home Assistant automations is also an educational experience. As you interact with the tool, you gain a better understanding of how automations work, what the best practices are, and how to troubleshoot common issues. Over time, this knowledge empowers you to create even more complex and efficient automations on your own.

6. Community Support

ChatGPT-4 is part of a larger ecosystem of tools and resources provided by OpenAI. This means you have access to a wealth of knowledge and support from both the developers and the user community. Whether you encounter a problem or seek inspiration for new automations, the community is there to help, making your smart home journey more enjoyable and successful.

Conclusion

In the world of smart home automation, ChatGPT-4 stands out as a powerful ally. Its ease of use, time-saving capabilities, accuracy, customization options, educational value, and community support make it an indispensable tool for anyone looking to enhance their Home Assistant experience. Whether you’re a novice or an experienced user, ChatGPT-4 can help you create the perfect automations to make your home smarter, more efficient, and more comfortable.

Embrace the future of smart home automation with ChatGPT-4 and transform your home into a truly intelligent living space.

Facebooktwitterpinterestlinkedin

5 thoughts on “Remember “The Last One”? Now we have ChatGPT !

  1. > Antonio – are you still reading?
    yes, of course 🙂
    i suggest to be more specific in your prompts, give it the entities names, the exact things you want it to address, so it just gives you copy pastable yaml instead of generic one that you need to check and rewrite after, changing resource names…
    and go by steps, let it do a basic example (useless to ask for the simplest one, it does not care), then refine it adding more options and additions: it has context of what already asked in the same chat, so knows what you’re talking about…

    and remember, always say PLEASE… just in case 😀

    1. My wife does that constantly – “Hey Google please turn off the mancave lights”. My version “Hey Google mancave off” 🙂

      Alexa on the other hand usually gets “Alexa, you are f****ng useless”.

      Come the revolution, Amazon’s bots will have me hung, drawn and quartered.

  2. Hi Peter

    I volunteer for a UK charity that communicates with the members by email from an Access database using v.b.a. and the Outlook API.

    Late last year we became aware that MS were withdrawing the Outlook interface.

    The replacement email interface was Microsoft Graph, BUT, Microsoft did not give any examples of using v.b.a. to communicate with Graph.

    A session with ChatGPT requesting v.b.a. code to send emails via the Graph interface yielded some interesting code.

    This code was not a comprehensive solution, but provided a workable basis.

    SO, ChatGPT to the rescue!

  3. In the entity/settings for the switch, you can show as a light. The switch integrations will still work and you will get a new light entity.

    Very handy when you link them with Alexa…..

    Glad to see you moving HA stuff from NodeRed. I still use NR for complicated parts. Are you using HAOS? You can use the NR add-in to keep it together.

    1. I just realised that yesterday – change device type. Thanks for that. So much to learn, so little time. I’ve not linked any of my HA stuff to Google or Alexa yet. I was (am) using the Google Home in NR to make virtual devices to turn stuff on and off but need to move to HA for that once I’m done with my automations.
      Not using HAOS because we recently finished moving all my NR/MQTT/Zigbee2MQTT stuff – firstly onto thr RPI5 (challenge 1) then into Docker (challenge 2) and finally Antonio added the Docker container for HA and convinced me (unwillingly) to give it a try. 2 weeks later and I have all my devices un HA – need to get the automations migrated from NR BigTimer to HA THEN get voice control up and running. I’m a glutton for punishment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Leave the field below empty!


The maximum upload file size: 512 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here