How do I always check if the accountant I created arrived at 1 hour and make a rule of three

I am creating an application to control the lamps in a house, I have for example the comfortable room and it has 2 lamps, then two buttons that turn them on and off and a control panel that shows through a switch if the lamp is on or no, now on the control panel under the lamp I want a text showing how much the lamp has spent, the timer I already did, I did it according to the image below.
Now I need him to be always checking, every switch so that every 1 hour on their counter make the rule of 3 and show the result, if you have 2 hours the same thing but with two now.
Remembering that (and this is my biggest doubt) I will have several lamps, so how do I do it? do I create a variable for each lamp? because when he turns off one of the lamps he cannot reset the time of the others.!

Yes. Each lamp will have to have its variable to register its time.
Just like someone on a skating rink …

Use a data entry so that the KWH value can be entered by the system administrator …

this idea was cool, but it will take some work hehe.
Initially I thought about making the image below.
however, he only checks when the button is clicked, he needed to always check if the time is at 1 or has passed.

could you explain it better? I think I didn’t understand the idea

Sorry :

Create an option for the user to change the kwh value ( database local , tinydb or sqlite). Or create an online database

Are you using web data? Are these blocks yours?

sorry, I forgot to take it out before sending it so as not to confuse it, yes, I am using data from the web, as I said it is an application to control the lights of a house, the application communicates with another iot platform (internet of things) that sends signal for Esp32 and controls the lights

1 Like

do you say a place where the user places when it is the kwh (in this case how much the light company charges) is that?
do I do this in the form of a question? in case you ask the user how much is charged and the result of this answer to use to calculate?
it makes a lot of sense, as each location is different from the amount charged.
I am going to try

1 Like

Yes . Create an option on the application screen (like the settings menu), where the user needs to define the KWH value of his state (RJ, SP, MG, ES, BA, RS …).
Ideally, in the first entry (the KWH value will be 0 in the tinydb) of the user in the application, you have already asked for the KWH value.
And then write that value to tinydb. In the next entries, as there is already a value other than 0, the application would not ask. If the user needs to change, he will use the settings menu.

This is very interesting and useful

OK, I’m working on it.
thinking about it, i believe i should ask the user along with the KWH also how many watts is his lamp, right?
since depending on the power of the lamp the cost will be different.

1 Like

thank you, I hope to be able to finish everything.

1 Like

Then your app will be more realistic: in the configuration menu, in addition to asking for the kwh value, you will also ask for the power of each lamp in each room.
But, you can go further:
the user can configure the house, creating rooms and associating lamps with rooms, power to lamps and type to lamps.

Bedroom 1 - lamp 1 - led - 9 w
Bedroom 1 - lamp 2 - led - 9 w
Bathroom - lamp 1 - led - 12 w

wow, the idea is great show!
but I have a deadline unfortunately, but I’ll try.
then in that case I would have to have a list in tinydb for each room, how could this be done?

Well, you would create 2 tables in sqlite, one to record the rooms (room name) of the house and another to record the lamps (power, type and room (to which room this lamp belongs)).
Lamp power and type do not vary, so they can be a Spinner or Listpicker.
Rooms can also come from a component (prevent the user from typing accurately - add something like Bathroom 1 Bathroom 2)

This is just an initial idea

I have some doubts, I am not a bank with a database (if my teacher listens it would be kind of sad).
so let’s go by parts, ok, I made the lamp and the power with Listpicker.
and without code I left it like this (as shown in the image below)
what I wrote there was:
“Create = CREATE TABLE lamps (power NON-NULL TEXT, type NON-NULL TEXT, like NON-NULL TEXT);”
I’m in the right way? and how do I call the data informed here after it on the control panel to make the calculation?
PS: I called with a procedure just because the button when Home starts up … it’s already full.

I don’t know if I understood correctly, can you explain it better? you say to put a Listpicker with names of rooms and the user to select, there in the home will be displayed what the user selects?

All 2 tables must have a primary key, autoincrement.
Since the table lamps will have, in addition to the primary key and auto increment, it will have a foreign key. This key, (numeric field and not null), is the room key. When inserting lamps, the user must define which room (previously registered) it belongs to. There is NO lamp without a room. There is comfort, room temporarily without a lamp associated with it.

Maybe :

Idcomodo not null autoincrement PK
Name Text

Idlampada not null autoincrement PK
Id_comodo numeric not null FK
LampType text
LampPower numeric

No. (but it wouldn’t be a bad idea). I suggested on the room registration screen. But forget it, let the user type the names of the rooms. But in the registration of lamps, there must be a listpicker with these pre-registered rooms to associate the lamps with the rooms.

After completing the registration of rooms and lamps, you must make a select sql in your tables. But this sql select routine depends on how your app’s layout will be.
How will it be?
1-All rooms on the same screen?
2-A room after the user selects which room?
Select lampower ,lamptype from lamps where id_comodo=result_from_listpicker

The labels “lampada 1” will be you, the developer, that will put on the screen (dynamically).

You could, but shouldn’t, put in each lamp record, 2 fields: hora_on and hora_off. It would not be ideal, because that way, you could not have a complete history of the lamp. With the history (another table), you could know how many hours the lamp lasted before it burned… and other things.

so in the configuration part there will be 3 questions, right?

  • What kind of lamp
  • What is the power of the lamp
  • Which room (previously registered) the lamp belongs to
    everything with Listpicker