¿Puedo encender el relé de mi calefactor en casa desde el móvil mientras estoy en el campus?
Traducido del English por IA ·
Primera publicación, perdón si este no es el lugar adecuado. Tengo una Pi Zero 2 W en casa con una placa de relés en GPIO17 que enciende un pequeño calefactor de aceite en mi habitación (sí, es un relé adecuado para ello, mi padre lo comprobó). Ya envía la temperatura de la habitación a Hermetry cada minuto con paho-mqtt.Lo que quiero: cuando salga de la biblioteca a las 21:00, encender el calefactor desde el móvil para que la habitación esté caliente cuando llegue. Encontré la aplicación de Hermetry, pero parece que es para notificaciones. ¿Puede también encender cosas? ¿O necesito abrir un puerto en el router y ejecutar una página web en la Pi? No sé muy bien cómo hacerlo de forma segura.
first post, sorry if this is the wrong place. I have a Pi Zero 2 W at home with a relay board on GPIO17 that switches a little oil heater in my room (yes it’s a proper relay rated for it, my dad checked). It already sends room temperature to Hermetry every minute with paho-mqtt.
What I want: when I leave the library at 9 pm, turn the heater on from my phone so the room is warm when I get back. I found the Hermetry app but it looks like it’s for notifications. Can it switch things? Or do I need to open a port on our router and run a web page on the Pi? I don’t really know how to do that safely.
Traducido del English por IA ·
El reenvío de puertos en el router funciona, lo hice una vez para una cámara. Solo elige un puerto alto.
Port forwarding on the router works, I did that for a camera once. Just pick a high port.
Traducido del English por IA ·
Por favor, no expongas una Pi a Internet con un «puerto alto». Tu Pi ya mantiene una conexión saliente con el broker, puedes enviar cosas por ahí.
Please don’t expose a Pi to the internet with a «high port». Your Pi already keeps an outbound connection to the broker, you can send stuff down that.
Traducido del English por IA ·
Ah, entonces la nube puede responderle al dispositivo? ¿Y cómo entra el teléfono en todo esto?
oh so the cloud can talk back to it? How does the phone come into it though?
Traducido del English por IA ·
Según la documentación, la aplicación móvil sirve para notificaciones y aprobaciones. Para el control, la consola web en el navegador del móvil funciona bien; así es como manejo la bomba de mi huerto.Qué configurar:
- En el perfil de dispositivo de la Pi, pestaña Commands, añade un comando, por ejemplo el método
heater.set, con un parámetro Sí/Noon, nivel Basic. Las placas solo envían comandos de nivel Basic. - Crea un panel, añade un control Switch, acción Run a command, elige la Pi y
heater.set, y vincula el estado actual a una clave que reporte la Pi (por ejemploheater_oncomo 0/1). - En la Pi:
def on_connect(c, u, f, rc):
c.subscribe("v1/rpc/req/+", qos=1)
def on_message(c, u, msg):
req_id = msg.topic.rsplit("/", 1)[1]
body = json.loads(msg.payload)
if body.get("method") == "heater.set":
on = bool(body["params"]["on"])
GPIO.output(17, on)
c.publish("v1/telemetry", json.dumps({"heater_on": int(on)}), qos=1)
c.publish(f"v1/rpc/res/{req_id}", json.dumps({"ok": True}), qos=1)
No se abre ningún puerto. Guarda la placa en la pantalla de inicio del móvil como marcador y funcionará prácticamente como una aplicación. Para las alertas (habitación demasiado fría, etc.), la aplicación envía notificaciones push al teléfono, o puedes usar el correo electrónico o una aplicación de chat vinculada.
From what the docs say, the mobile app is for notifications and approvals. For the switch, the web console in the phone browser works fine, that’s how I run my allotment pump.
What to set up:
- On the Pi’s device profile, Commands tab, add a command, e.g. method
heater.set, one Yes/no parameteron, tier Basic. Boards only send Basic tier commands. - Make a dashboard, add a Switch control, action Run a command, pick the Pi and
heater.set, and bind the current state to a key the Pi reports (sayheater_onas 0/1). - On the Pi:
def on_connect(c, u, f, rc):
c.subscribe("v1/rpc/req/+", qos=1)
def on_message(c, u, msg):
req_id = msg.topic.rsplit("/", 1)[1]
body = json.loads(msg.payload)
if body.get("method") == "heater.set":
on = bool(body["params"]["on"])
GPIO.output(17, on)
c.publish("v1/telemetry", json.dumps({"heater_on": int(on)}), qos=1)
c.publish(f"v1/rpc/res/{req_id}", json.dumps({"ok": True}), qos=1)
No ports opened. Bookmark the board on your phone’s home screen and it’s basically an app. For alerts (room too cold etc.) the app gives you push on the phone, or use e-mail or a linked chat app.
Traducido del English por IA ·
¡funciona!!! Probado desde el autobús. Una cosa que me hizo tropezar: primero creé el comando como Privileged porque conmuta la red eléctrica, y el interruptor de la placa decía que no se puede enviar desde una placa. Lo cambié a Basic y funcionó. Además, ahora me suscribo en on_connect como escribiste; antes dejaba de funcionar después de que el Wi-Fi de la Pi se cortara un momento.
it works!!! tested from the bus. One thing that tripped me: I first made the command Privileged because it switches mains and the switch on the board just said it can’t be sent from a board. Changed it to Basic and it went through. Also I subscribe in on_connect now like you wrote, before it stopped working after the Pi’s Wi-Fi blipped.
Traducido del English por IA ·
Tienes razón, la conexión saliente es más limpia. Retiro mi consejo sobre el reenvío de puertos.
Fair enough, outbound is cleaner. Taking my port forwarding advice back.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

