Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
SgtBot

Smart home programming applications with Raspberry Pi

Recommended Posts

Posted · Original PosterOP

Hi,

 

I'm currently trying to set up some quality of life smart home applications with a raspberry pi 4 I recently got. Right now all it has on it is pi-hole to filter out all of the ads on my network. My goal is to be able to have the raspberry pi be able to send a wake on lan packet to my computer when I either tell my google home to turn on my computer and/or when it detects that my phone's mac address has reconnected to my home network. I would also like to be able to have the reverse happen, I want to send a command to my computer (running windows 10 home) to shut down on either of the above conditions (except obviously when my phone's mac address leaves the home network).

 

Here are my basic quesions:

  • What is the most effective way to send a wake on lan packet from a raspberry pi to another device on the same network?
  • Is there a Python library that would allow me to send WOL packets?
  • Would I have to enable remote registry on my windows machine or is it possible to write a custom windows application that listens for instructions from the pi and executes a batch file to shut down?

I can probably figure out how to listen for ifttt requests on the raspi and have the pi execute a command or script in response... but any suggestions on how to do this efficiently would be greatly appreciated!

 

Any other smart home ideas like this with the pi would be welcomed as well. I'm currently working on modifying the pi to act as a smart thermostat as well to work with an AWS server so I can control my apartments temperature from anywhere.

 

Thanks!

Link to post
Share on other sites

You can have look at home assistant.


Magical Pineapples


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Link to post
Share on other sites

You can use wol and embed it in a script. You do need to enable WoL functionality on your target computer. There's an article about this on the Arch wiki, it should apply to Raspbian too.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
Posted · Original PosterOP
15 minutes ago, Sauron said:

You can use wol and embed it in a script. You do need to enable WoL functionality on your target computer. There's an article about this on the Arch wiki, it should apply to Raspbian too.

Thanks!

 

I already have WOL enabled but i just use an app from my phone to send the packet. I just need to have it automate itself on certain conditions from a rpi

Link to post
Share on other sites

From what you have described the windows machine power up and shut down trigger the same on the pie.

 

In which case just make windows turn on the pi after it boots and turn it off before it shuts down.


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites
Posted · Original PosterOP
3 hours ago, Hans Christian | Teri said:

Might want to take a look at this for a Python wake on lan script.

Thanks! I made a basic python script to implement that. I assigned my phone's mac address a static IP through DHCP on my router so I could still have the phone utilize pi-hole. Then I have the script ping that IP until it gets a successful ping, upon which it will send a magic packet to wake up the computer.

 

The only issue is that it will keep repeatedly sending magic packets while my phone is on the network, so I've just got to edit it to send once on a successful ping to phone.

 

I'll probably end up setting a variable to count how many wake on lan packets have been sent, and then increment it on each one. Then to make sure it actually wakes up the computer, I'll have the script ping my computer's IP and if the computer is still off it will reset the WOL packet counter to zero and try again.

 

Idk if thats the most effective but it seems like a good shot so far

 

Here's what I've got so far if you're curious:

import os
import time
from wakeonlan import send_magic_packet

hostname = "1.1.1.1" #My phone

while True:
  time.sleep(20)
  response = os.system("ping -c 1 " + hostname)
  if response == 0:
    print("Owner phone detected on network, sending magic packet...")
    send_magic_packet('aa:bb:cc:dd:ee:ff') #Sends WOL packet to computer
  else:
    print("Owner phone offline, retrying...")
    pass

 

Link to post
Share on other sites
4 hours ago, SgtBot said:
  • What is the most effective way to send a wake on lan packet from a raspberry pi to another device on the same network?

not sure what you mean by effective. wol is a simple packet like any other but with a specific content and target. id start by looking into what a wol packet looks like and youll understand.

Quote
  • Is there a Python library that would allow me to send WOL packets?

im sure there are but they are not neccessarily neccesary

Quote
  • Would I have to enable remote registry on my windows machine or is it possible to write a custom windows application that listens for instructions from the pi and executes a batch file to shut down?

push2run , google it. does exactly that. triggered by a pushbullet message. can even configure over ifttt directly so no pi neccessary. but i would try looking into wether you can just send windows to sleep from another machine. with shell commands. i know you can from one windows machine to another but not sure about a pi. 


"I know its stupidly overdone and unreasonably unneccesary but wouldnt it be awesome if ..."

 

CPU: Delidded i7 7700k (watercooled) Cooling: 3x 360 rads by Alphacool  MB: ASUS z270i  RAM: G.Skill Trident Z RGB 16GB  GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled)  DISPLAY: LG 34UC88-B 21:9 1440p SSD(OS): Samsung 960 EVO 250GB SSD(Games): Corsair MP510 960GB SSD(Applikations): Samsung 850 EVO 500GB  HDD(Scratch): WD Blue 500GB HDD(Downloads): WD Blue 320GB HDD(Long-term): WD Green 2TB (external)   PSU: Corsair SF750 Case: Lian Li PC-O11 D Mouse: Logitech MX Master Keyboard: Logitech G513 Carbon

 

Link to post
Share on other sites
Posted · Original PosterOP
14 hours ago, cluelessgenius said:

not sure what you mean by effective. wol is a simple packet like any other but with a specific content and target. id start by looking into what a wol packet looks like and youll understand.

im sure there are but they are not neccessarily neccesary

push2run , google it. does exactly that. triggered by a pushbullet message. can even configure over ifttt directly so no pi neccessary. but i would try looking into wether you can just send windows to sleep from another machine. with shell commands. i know you can from one windows machine to another but not sure about a pi. 

Thanks, I'll look into that. I think I've got some pretty good baseline code for it. For the pushbullet one, I use that as well. I have my google nest hub send a pushbullet command to my phone, which uses Automagic on my phone to send a WOL packet to my pc. I used Automagic because Taskr didn't have native WOL support.

 

Here's the code I have so far, I'll look into implementing that push2run into the code if I can:

import os
import time
from wakeonlan import send_magic_packet

phone = "1.1.1.1" #Phone IP address
computer = "2.2.2.2" #Computer IP address

while True: 
  time.sleep(20) #Ping for computer and/or phone every 20 seconds
  phone_response = os.system("ping -c 1 " + phone) # Initial ping for phone
  if phone_response == 0:
    print("Owner phone detected on network, sending magic packet...") # Sends WOL packet if phone is detected
    send_magic_packet('aa:bb:cc:dd:ee:ff')							
  else:
    pc_response = os.system("ping -c 1 " + computer)  
    if pc_response != 0: # This block checks if waking up the computer was waked
      print("Owner computer still offline, resending magic packet...") # and continues to ping until successful
      send_magic_packet('aa:bb:cc:dd:ee:ff') 
    else:
      print("Owner phone and computer online, standing by...") # If owner and computer are both online, don't send any packets
      pass
  else:
    print("Owner phone offline, retrying...") # If phone is offline, start script over
    pass

 

Link to post
Share on other sites

@SgtBot 

well i myself had it running like that for a while.

using push2run to shutdown/hibernate over ifttt and pushbullet

and using automate on my smartphone over pushbullet and ifttt to wol

but right now im looking for a way to exclude google and alexa completly from my home setup. looking at habot and similar but with no real luck yet.

o for now im sticking with having google/alexa commands send a pushbullet and then i got a bit of server software to catch pushes and do stuff depending on the command.

what im missing is the ability to turn it around and have my server trigger google/alexa to say stuff when events accour. i know it must be possible since skype and so on already let alexa ring and stuff so a bit more research needed here.

 

anyway i digress.

if you want to use pushbullet to forward google/alexa commands to a server like i do heres the most basic code to quickly catch pushes (although im writing in c# since my server is a surface 3 pro with windows 10 :D but maybe it helps) - but again written in C# and with the help of PushbulletSharp  and so on. im sure theres libraries for python or whatever you wanna use too. and pushbullet themselves have great documentation on their API

using PushbulletSharp;
using PushbulletSharp.Filters;
using PushbulletSharp.Models.Responses.WebSocket;
using System.Web.Script.Serialization;
using WebSocketSharp;

string apikey = "YOUR PUSHBULLET API KEY";
JavaScriptSerializer js = new JavaScriptSerializer();
Client = new PushbulletClient(apikey, TimeZoneInfo.Local);
lastChecked = DateTime.Now;
pushlist = new Dictionary<string, string>();

ws = new WebSocket(string.Concat("wss://stream.pushbullet.com/websocket/", apikey));
ws.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
ws.OnMessage += (sender, e) => 
{
	WebSocketResponse response = js.Deserialize<WebSocketResponse>(e.Data);

	switch (response.Type)
	{
    	//ping to see if connection is still active, comes in in intervals
        case "nop":
        //Console.WriteLine(string.Format("Updated {0}", DateTime.Now));
        break;

        //notification that something has changed - device,push
        case "tickle":
        //Console.WriteLine(string.Format("Tickle recieved on {0}. Go check it out.", DateTime.Now));
        PushResponseFilter filter = new PushResponseFilter()
        {
        	Active = true,
            ModifiedDate = lastChecked
        };

        var pushes = Client.GetPushes(filter);

        foreach (var p in pushes.Pushes)
        {
        	if (!pushlist.ContainsKey(p.Body + "|" + p.Created))
            {
            	//Console.WriteLine(p.Body + " : " + p.Created);
                pushlist.Add(p.Body + "|" + p.Created, p.Body);

                //if a push is newer than the lastchecked flag
                if (DateTime.Compare(p.Created, lastChecked) > 0)
                {
                	lastChecked = p.Created;
                    
                  	//do whatever you want to do in here. 
                    //probably wanna switch between different push messages.
                    //p.body contains the message of the push for me
                }
            }
        }
        break;

      case "push":
      	break;

      default:
        break;
    }
};

 


"I know its stupidly overdone and unreasonably unneccesary but wouldnt it be awesome if ..."

 

CPU: Delidded i7 7700k (watercooled) Cooling: 3x 360 rads by Alphacool  MB: ASUS z270i  RAM: G.Skill Trident Z RGB 16GB  GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled)  DISPLAY: LG 34UC88-B 21:9 1440p SSD(OS): Samsung 960 EVO 250GB SSD(Games): Corsair MP510 960GB SSD(Applikations): Samsung 850 EVO 500GB  HDD(Scratch): WD Blue 500GB HDD(Downloads): WD Blue 320GB HDD(Long-term): WD Green 2TB (external)   PSU: Corsair SF750 Case: Lian Li PC-O11 D Mouse: Logitech MX Master Keyboard: Logitech G513 Carbon

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×