-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Conditions #1806
Comments
another use case could be |
Difficult. We don't have |
Ok, i've made a test-version with binaries: And these are the rules for conditions and arithmetics:
A few use cases are mentioned above. If users have other, please mention here, we can collect and add to the wiki. |
Very excited about this feature! I would just do a PR on dev and let the community test. |
PR done, dev.17 |
thanks, I'll review. With "actually the condition is checked every 10 sec. (Gives time to deactivate the schedule in case of esp crash, please report if there are crashes)" where is this defined? I couldn't spot it quickly. |
see here: WebSchedulerService.cpp#L412-L417 |
@MichaelDvP shall I take your instructions above and add it to the EMS-ESP docs/wiki? |
Yes, but i make some edits first and add:
|
ok let me know when you're done with the edits. |
Already done., edited #1806 (comment) I'm testing multiple instances of |
doc updated |
Good job. This new feature could help me unfortunately it doesn't work as I would have imagined. OnChange: Both BTW: Is there any way to set multiple output values? For example, set relay1 on and set relay2 off. |
Good catch. There are some special entities in ems-esp, that are not from ems and needs extra handling, i forgot to add them to scheduler. Multiple output commands and values are difficult in the actual structure, needs a lot of refactoring. |
Thank you for the fix. An extra schedule for each command is not equivalent to multiple actions because it doesn't guarantee action order. Is it possible to add to the "system Info" time-related items? e.g. dow, day, month, year, hour, minute
Scheduler2:
|
See last point here #1806 (comment) |
Michael, I was talking about onCondition, not onChange in the example above. If I understand correctly, the system items should be available in onCondition mode. Right? If onCondition is evaluated every 10 seconds, it might not be a performance issue. |
Ah, sorry, yes, system entities are available in condition mode. |
Completed. |
@proddy Should we add for the schedule command a simple http request. This is what i've tested with tasmota plug:
|
I've tried with typos in url and non-existing IPs, no issue. Too large response could be an issue, i'm not sure if we need the response at all. For now i only use it to check if it works (log) (switching the tasmota plug of my desk-light is the second test).
Do you have an example for this? I think mostly the http get returns not a single value and needs further parsing. |
Example: I could read a value from another EMSESP system via API: Do you plan to add HTTP requests to the onChange or onCondition types? Using math and conditions applied to the response payload would be nice. For example, you can set a dhw temperature based on the temperature of the secondary heater. |
I don't think this is a real use-case. Yes, the ems-esp api can respond with a single value, but this is very uncommon. I only want to add it as single command, just http, no response checking, no https, no authentification, etc. I've found only one usecase: building a useless box with my desk light: |
Another idea, more complex, is to create a new command (called REST or HTTP for example) that has as its value/data JSON these 4 keys: a URL, a Type which is either post or get, a Header string and a body. That way we can call Home Assistant services and scripts. I tested from a command line calling HA with: curl -X POST \
${ha_url}/api/services/script/test_notify \
-H "Authorization: Bearer ${ha_token}" \
-H "Content-Type: application/json" |
Michael, another hypothetical example (it's not my case): you have two boilers, usually only one is running, but if necessary the other one comes on. This is either due to power needs or simply for maintenance. If each boiler had its own EMSESP controller, then the value set by remote status would be a good feature. The backup boiler would just check the status of the primary, and if it was in the off state, or the return temperature was low, the second boiler would come on... This could then be easily done via that HTTP request to the API of the primary boiler. This way there would not even be a need for HA. Two or more boilers are often used for apartment buildings, but as I wrote, this is not my case, it could be quite a useful feature. It seems to me that the scheduler is getting quite complex, and there could be difficulties in distinguishing what is an ESP command, what is a URL, what is a string, and what is a number. Just wondering if it would like some refactoring, and to distinguish between a command and a string. I know that commands can be parenthesized, but in some cases, the parenthesized command didn't work for me. This is not a criticism of the code, currently, the scheduler does everything I need it to do, but it's just a thought for future extensions... I like Prody's example, but it adds complexity to specifying parameters again. It's hard to put everything that into just the Condition, Command, and Value triplet. If you plan on extending the scheduler, it might be nice to consider some kind of expert scheduler setup. Something like a script? |
@proddy Yes, this could be a way to add the authorization header.
@jannejman Not a convincing example, in this case you should mount a ems-cascade module (MC400). |
@MichaelDvP I like it. Let's do it. It'll make EMS-ESP very powerful |
I've added it to the PR, bin is https://github.com/MichaelDvP/EMS-ESP32/releases |
the http works well. I was able to call Home Assistant scripts via the scheduler, which is fantastic. I'll merge the PR, and we can continue to enhance it. Two changes needed
I'll make some changes. |
Agree, but special code is not very intuitive, I suggest:
I think setting a header should have priority, so check:
|
yeah, I had already coded it like below, before seeing your response. we're close:
|
I have made the scheduler loop async now. takes ~6k ram with 4k stack set. Testing now. |
nice! I've just merged into some small changes |
I think there may be a memory leak somewhere with the HTTP calls - haven't looked at it yet. on my E32v2 free mem dropped from 175 KB to 43KB. Same with max alloc. With no scheduler items, free mem is now at 137 KB on dev-26, so 38KB is being used up somewhere. |
What schedules were you running? How long? |
Is this with onChange queing strings or the actual dev? |
I think it must have been an issue with the upload script I was using. I'm taking now the .bin from GitHub CI and its working fine with I did notice with an E32V2 clicking on the web download downloads the wrong file (not the _16M) so I'll fix that |
Oh, i think that's what happend to @tp1de. I've tried if it save memory if we load HTTPClient dynamic, e.g.
but can not see any difference in heap/maxAlloc. Tested on a standalone S3 without bus-connection, only activated or deactivate schedules with http get/post. |
Yes, I can confirm (I haven't recognized). I need to flash the gateway to get it working again. |
I think we can close this, it works fine unless you can think of more things we can add or improve? |
Yes, i close it for now.
There is still a lot to think about. |
Yeah, I always like the idea of email (copying the feature from https://husdata.se/docs/h60-manual/notifications/). Pretty sure we discussed it before, but can't remember where. We have the The SMTP can be added to settings, like my Unifi network does: This would be a new Feature GitHub issue, we can still keep this closed and play around in a separate fork. If |
Oh, i have not husdata in mind, The notification is a feature of a lot of 24/7 deviceslike routers, NAS, etc. Also tasmota have it. https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_01_1_webserver_mail.ino But email is for people today not fast enough, They want push notification like whatsapp, or sililar and there are a lot of web services (payed) that can be used via http(s). (Still thinking) |
I use HA's notify to send Push messages that get triggered on EMS-ESP events. I've also used Pushover before. We can use it now using their REST interface and the nice work you did on the Command handling HTTP calls. The API is similar to HA's, just need to provide a Token. https://pushover.net/api |
By @MichaelDvP :
We have talked about conditions some time ago here, in scheduler discussion and when implementing custom variables. I now have a first implementation of conditions for the scheduler. My own use case is to use the relais of gateway V2 to control the solar assist valve, now done by ioBroker script and a sonoff module. To control i need a expression parser for logical and arithmetric functions.
relais on for
mixer/hc2/pumpstatus == 1 && solar/cylbottomtemp > (temperaturesensor/boiler_backflow + 4)
relais off for
mixer/hc2/pumpstatus == 0 || solar/cylbottomtemp <= temperaturesensor/boiler_backflow
First implementation looks like this:
and is working now (but still crashes if the condition could not be parsed correctly).
Another possible use case is for users without thermostat to implement a heatingcurve, than calculate the command value:
Also implemented is a possible trigger on change, e.g. the heatingcurve can be recalculated on every change of outdoortemp, not periodic.
I'll fix the crashes and make a feature-build for testing.
Originally posted by @MichaelDvP in #1704 (comment)
The text was updated successfully, but these errors were encountered: