Use Copilot (Chat GTP?) to help writing rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
wrbrower
Normal user
Posts: 10
Joined: 16 Oct 2016, 17:18

Use Copilot (Chat GTP?) to help writing rules

#1 Post by wrbrower » 08 Jan 2025, 03:01

I threw this at Copilot and received an actual answer.
It appears to be knowledgeable of things like ESP EASY rules.

Within ESP EASY rules, convert 24 hour time to 12 hour time

Certainly! In ESP Easy, you can use rules to convert 24-hour time format to 12-hour time format. Here's an example of how you can achieve this using rules in ESP Easy.

You will need to use some basic arithmetic and conditional logic to handle the conversion. Below is a sample rule script that demonstrates the conversion process:

rules
on System#Boot do
timerSet,1,10 // Set a timer to update the time every 10 seconds
endon

on Rules#Timer=1 do
// Get the current hour and minute
Let,1,%sysyear%
Let,2,%sysmonth%
Let,3,%sysday%
Let,4,%syshour%
Let,5,%sysminute%

// Convert 24-hour time to 12-hour format
If [var#4] > 12
Let,6,[var#4]-12
Let,7,PM
Else
If [var#4] = 0
Let,6,12
Else
Let,6,[var#4]
EndIf
Let,7,AM
EndIf

// Format the time as hh:mm AM/PM
Let,8,[var#6]
Let,9,[var#5]
Let,10,[var#8]:[var#9] [var#7]

// Output the formatted time
Publish,device/time,[var#10]

// Restart the timer
timerSet,1,10
endon
In this example:

The current hour (%syshour%) is checked.

If the hour is greater than 12, it subtracts 12 to convert it to 12-hour format and sets the period to PM.

If the hour is 0, it sets the hour to 12 and the period to AM.

It formats the time and publishes it to a topic called device/time.

This is just one way to handle the conversion using ESP Easy rules. Feel free to customize it based on your specific needs!

TD-er
Core team member
Posts: 9878
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Copilot (Chat GTP?) to help writing rules

#2 Post by TD-er » 08 Jan 2025, 07:53

Nice, however it will not work like this as we don't yet support string formatting to be stored in variables.

But with some minor changes, it can be made to work like this.


You could also use one of the many system variables with "_am" in the variable name as shown on the system variables page...

Code: Select all

%lcltime%           2025-01-08 06:48:38 
%lcltime_am%        2025-01-08 6:48:38 AM   
%systm_hm%          6:48
%systm_hm_0%        06:48   
%systm_hm_sp%       6:48    
%systm_hm_am%       6:48 AM 
%systm_hm_am_0%     06:48 AM    
%systm_hm_am_sp%    6:48 AM 
%systime%           06:48:38
%systime_am%        6:48:38 AM  
%systime_am_0%      06:48:38 AM 
%systime_am_sp%     6:48:38 AM

User avatar
ThomasB
Normal user
Posts: 1358
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Use Copilot (Chat GTP?) to help writing rules

#3 Post by ThomasB » 09 Jan 2025, 18:12

Wow. I asked copilot to create an ESPEasy rule to display DS18B20 temp on an LCD and the results were believable.

The AI overlords are going to replace us all. I just hope they keep me as a pet.

- Thomas

TD-er
Core team member
Posts: 9878
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Use Copilot (Chat GTP?) to help writing rules

#4 Post by TD-er » 09 Jan 2025, 19:32

I'll be truly impressed when ChatGTP will fix the Espressif WiFi code.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests