Skip to content
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: Add support esphome api for power plug #70

Open
tayanov opened this issue Jan 21, 2021 · 8 comments
Open

Feature: Add support esphome api for power plug #70

tayanov opened this issue Jan 21, 2021 · 8 comments

Comments

@tayanov
Copy link

tayanov commented Jan 21, 2021

Please add support esphome api for power plug.
If you show home assistant config and use tasmota power, may be you can add support [power printer] and [power device_name] with esphome restapi ?
https://esphome.io/web-api/index.html
I use sonoff pow2 on esphome. i see powermeter and can turnon off printer from home assistant, but not from Fluiid or other klippers web gui.

@tayanov
Copy link
Author

tayanov commented Jan 27, 2021

or may be add simple pull http url e.g. wget or curl as [power printer]

@alexpthe1
Copy link

alexpthe1 commented Jan 28, 2021

or just the possibility to run a shell script #61

@Arksine
Copy link
Owner

Arksine commented Jan 31, 2021

As mentioned in issue 61, simple url's won't work with the power plugin, as it must be able to query the state of the device. The tasmota device was contributed by a user. Someone who owns a "esphome" device is free to contribute an implementation.

There are major security implications with running configurable scripts, so it is unlikely that I add that ability.

@tayanov
Copy link
Author

tayanov commented Feb 3, 2021

As mentioned in issue 61, simple url's won't work with the power plugin, as it must be able to query the state of the device. The tasmota device was contributed by a user. Someone who owns a "esphome" device is free to contribute an implementation.

There are major security implications with running configurable scripts, so it is unlikely that I add that ability.

ok, im migrate to tasmota, but its not work, with any config i see that

Fluidd warnings found.
Moonraker has failed plugins, please check your logs, update your configuration and restart moonraker.
power
Moonraker plugin configuration can be found here.

its my config
[power printer]
type: tasmota
address: 10.0.0.100
output_id: 1

i try anything config but hope is die)

and if i go to
http://10.0.0.100/cm?user=admin&password=&cmnd=Power1%20off printer is off. tasmota work

@Arksine
Copy link
Owner

Arksine commented Feb 3, 2021

Moonraker.log should tell you what the error is. I suspect it is because device query failed, but I won't be able to tell without the log file. If that is the case, you need to make sure that SetOption26 is set in Tasmota.

@tayanov
Copy link
Author

tayanov commented Feb 4, 2021

i comment 13 line at power.py #import gpiod
and all works. its trouble as #75
then i try ./install-moonraker.sh -r
uncomment 13 line at power.py import gpiod

and all ok. but...

i can turn off printer from web fluiid macros button, but cant POWER ON from macros button.
!! Lost communication with MCU 'mcu'

macros for power on not work with power_off mcu.

But all work from top/right popup menu.
Thanks ...

@Arksine
Copy link
Owner

Arksine commented Feb 4, 2021

You can't power on with a GCode Macro as Klipper can only execute RESTART and FIRMWARE_RESTART when it is in the shutdown state. You must use the API to power on.

@iJebus
Copy link

iJebus commented Jul 5, 2023

Not to go resurrecting a dead issue, but on the basis of the title, I think this can be closed. I'm controlling an ESPHome power plug using the generic HTTP config, e.g.

[power SV06]
locked_while_printing: True
restart_klipper_when_powered: True
type: http
on_url: http://x.x.x.x/switch/athom_smart_plug_v2/turn_on
off_url: http://x.x.x.x/switch/athom_smart_plug_v2/turn_off
status_url: http://x.x.x.x/switch/athom_smart_plug_v2
request_template:
  {% if command in ["on", "off"] %}
    {% do http_request.set_method("POST") %}
    {% do http_request.set_body({}) %}
  {% endif %}
  {% do http_request.send() %}
response_template:
  {% if command in ["on", "off"] %}
    {% do async_sleep(1.0) %}
    {% do http_request.set_method("GET") %}
    {% do http_request.set_body(None) %}
    {% do http_request.set_url(urls.status) %}
    {% set response = http_request.send() %}
    {% do response.raise_for_status() %}
  {% endif %}
  {% set resp = http_request.last_response().json() %}
  {resp["state"]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants