xoseperez / espurna

Home automation firmware for ESP8266-based devices
http://tinkerman.cat
GNU General Public License v3.0
3k stars 638 forks source link

Enable/ disable scheduler(s) via MQTT #2617

Closed bopnrgi closed 1 month ago

bopnrgi commented 2 months ago

Description

Is it possible to add topics on MQTT to enable or disable schedulers via MQTT ?

For iot behind 4G router without home assistant it can manage water boiler easily (for example)

Solution

No response

Alternatives

No response

Additional context

No response

mcspr commented 2 months ago

Do you mean something akin to HTTP API, where settings are overwritten and enabled / disabled state persists? Would it be ok if 'enabled' / 'disabled' state is not persistent and would reset after device reboots?

Does this also mean there has to be a way to know the current state? Probably other portions of the config as well? 'Restore' and 'Time'

edit: Time ranges (i.e. 10-15:00, Mon-Fri, etc.) are not an option here?


Right now, MQTT terminal option can be enabled. Then, publishing to $device/cmd/set payloads like set schType0 disabled to enable, set schType0 calendar to turn it back to 'Calendar' type.

bopnrgi commented 1 month ago

Hello, thanks for your reply :) Context : My device is behind a 4G box, so it's not possible to use HTTP API (4G terminal don't have public IP on 4G Network). That's why i wanna use MQTT to control it. This exclude HTTP API...

I wanna use a MQTT topic to turn on/off any scheduler (and persist state at reboot, but the firmware do it now..) like a switch.It could be : <root>/scheduler/#/set (replace # by id of scheduler) set schType0 disabled seems not work

Screenshot_20240905-010743

mcspr commented 1 month ago

I wanna use a MQTT topic to turn on/off any scheduler (and persist state at reboot, but the firmware do it now..) like a switch.It could be : /scheduler/#/set (replace # by id of scheduler)

That is exactly why I am asking. MQTT is not request -> response exactly, but publisher -> subscriber w/ possibly multiple publishers and e.g. 'retain' flag that may introduce some quirky side effects.

set schType0 disabled seems not work

Should work with 1.16.0+ and with TERMINAL_MQTT_SUPPORT flag As there is no ENABLED / DISABLED state anymore. Types of schedule can be changed, one of which is 'disabled'. Meaning, changing it back to 'calendar' enabled it back.

There are also more options for time control, if that is what you actually need. See the Scheduler Wiki https://github.com/xoseperez/espurna/wiki/Scheduler

mcspr commented 1 month ago

Let's start with <root>/settings/+/set, which was the easiest out of the options above. Either enable this flag when building https://github.com/xoseperez/espurna/blob/00c972c5acd44c55f1bf50cbd055290b8cb0c78a/code/espurna/config/general.h#L1113 or set mqttSettingsEnabled 1 and reload in the terminal (via telnet, serial or webui debug panel)

ESPURNA-123456/settings/schType0/set => disabled should change the type to the disabled one ESPURNA-123456/settings/schType0/set => calendar goes back

No state is published back, though, since this handles generic key->value settings (and idk how to go about publishing anything from there just yet)