[SOLVED] Rule for restarting pi

hey guys,
running openhabian.

is there away to make a rule to reboot the pi.

currently i have a rule but its not rebooting

rule "reboot system"
when
    Item SystemReboot received command "ON"
then
    executeCommandLine("sudo reboot")
    logInfo("FILE", "reboot?")
end

any help would be good thanks

For this to work take a look at the Exec binding and here for an example.

thanks @H102,

i did search the fourm. must have used the wrong order of words when looking

There should not ever be a need to reboot the Pi, let alone from inside OH.
So wondering why you’re asking for this? Most people asking for this have some kind of problem they believe can be fixed by rebooting the server, but that’s just fighting symptoms and never the solution.
Better go analyse and fix the root cause.

2 Likes

hey @mstormi,
currently im changing some code on a teensy 3.2 conntroled via usb serial.(similar to a arduino).
every time i update the code on the teensy i have to unplug the usb serial connection and plug it back in after updating it, but openhab wont connect to it unless i reboot it.
but when i reboot the openhab sometimes the sony binding wont connect to the tvs unless they are on to start with.
in my rule i still need to add a turn on sony tvs before reboot to make sure they stay connected to openhab.

Well I don’t know what teensy is so I don’t understand why you’re doing that but you shouldn’t unplug Pi USB devices that OH has a serial connection open to because on re-plugging they can be assigned a different port.
If OH does not use that port (and I don’t understand why it should because if you would want to connect OH to an Arduino you wouldn’t use USB or serial for that) then there’s no effect so it should continue working.
I guess you should better ‘untangle’ your HW setup rather than to restart OH or the Pi.

You can add this to check if the tv is on and if not turn it on with a 30 second delay to make sure everything has time to start.

if(tv_item == OFF){
        tv_item.sendCommand(ON)
        startTimer = createTimer(now.plusSeconds(30), [|
           // Your reboot rule goes here.//
            startTimer = null
        ])
    }

how else do you connect to a Arduino if not via serial?
when i have unpluged and pluged in the arduino type device it has always shown up as the same device on ttyACM0 (not sure why its ACM0 instead of USB0+ but has never changed (so far)).

not quite sure what you mean by untangle you hardware setup. all that is connected is network and a usb cable to the arduino type device that is used for serial commutations using serial binding.

I don’t understand why you connect an Arduino to the Pi at all. It depends on the application, but normally you can use the Pi’s GPIOs or a hat so you don’t need any Arduino.
If you still do, there’s multiple alternative ways of connecting, the most popular way is via WiFi(or Ethernet) + MQTT. That’s what I mean by ‘untangle your HW setup’. That setup is the root cause of your problems, OH isn’t.

1 Like

ok. teensy hasnt had the library for mqtt ported over yet. some of the community have done so but is unstable. i was using html to control it for a while but there was something wrong with my code on it and it would lock up when it received to many commands. so far i havnt been able to lock it up over serial. reason im using the teensy is it is controlling a lot of my house before i new about openhab. so its controling quite a bit of the house that i havent gotten around to moving over to openhab yet. lights via dmx. blinds via rs485, relays, plus some other things.

You need to decide yourself where to control your house from, and I’d strongly recommend OH for this to become the lead, so move your functions off teensy and over to OH.
Once more, untangle your HW. Enable WiFi/MQTT on your teensy (maybe ok to use the unstable version if it’s just for a short period you need to migrate the functions to OH). Or move it to another Pi and use ser2net to bridge the serial interface over the network.

You should be able to just restart the binding that uses that port. The problem is that the binding maintains a lock on the device (e.g. /dev/ttyUSB0). When you unplug the USB, the old device file sticks around. When you plug it back in it sees that /dev/ttyUSB0 is still in use so it comes back as /dev/ttyUSB1.

If you stop OH or stop the binding (through the Karaf console before removing the USB and then start it once you add it again you will not have this problem. You can solve this problem just by restarting the binding (Karaf console). You can solve this problem by restarting OH.

As Markus said, you don’t need to reboot the whole RPi.

I connected an Arduino and rPi via USB and communicate with the serial binding. Reasons for doing this:

  • I needed pwm outputs for controlling dimmers, there are no pwm outputs on the rPi
  • I use the Arduino to control lights (dimmers and switches). You could say that an Arduino, being a microcontroller, is more suited for input/output control than a raspberry pi with a full blown OS
  • At the time you needed an Ethernet or wifi shield to communicate over a network and I was space limited
  • Finally, and this has been really helpful a few times already, my rPi and Arduino are in the basement. Since the USB connection is available I can code and download to the Arduino from the rPi using vnc. This way I don’t have to run down and plug my PC in everytime I’m updating the Arduino’s code.

I’m not saying using an Arduino is the wrong approach in your case, but RPi does have PWM capabilities.

Maybe I don’t understand but either of those shields tend to be significantly smaller than an RPi.

There are a number of libraries that allow for OTA updates to an Arduino. All of the ESP8266 firmwares like Tasmota and EPS Easy use this.

At the time you needed an Ethernet or wifi shield to communicate over a network and I was space limited

Maybe I don’t understand but either of those shields tend to be significantly smaller than an RPi.

The arduino had to be small enough to fit on a custom breadboard. I used an Arduino nano. If I wanted to communicate between rPi and Arduino via the network (like Markus said) I needed a network shield.

I wasn’t aware of the OTA (Over The Air right?) libraries out there until now. I probably should have guessed that something like that was possible :slight_smile:. It was one of my first projects, that’s why I went for the ‘start small and simple’-approach. I see the limitations of using the serial connection, but I just wanted to point out that it has some advantages too. But off course, everything depends on the application.