New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Can I switch my heater relay at home from my phone while I’m on campus?

Can I switch my heater relay at home from my phone while I’m on campus?

Solved 6 4

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.

♥ 2

Port forwarding on the router works, I did that for a camera once. Just pick a high port.

Measure twice, poll once.
♥ 1

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.

♥ 0

oh so the cloud can talk back to it? How does the phone come into it though?

♥ 0

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:

  1. On the Pi’s device profile, Commands tab, add a command, e.g. method heater.set, one Yes/no parameter on, tier Basic. Boards only send Basic tier commands.
  2. 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 (say heater_on as 0/1).
  3. 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.

Accepted solution♥ 1

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.

♥ 1

Fair enough, outbound is cleaner. Taking my port forwarding advice back.

Measure twice, poll once.
♥ 2
Viewing 7 posts – 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Join the conversation

Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

Share