Announcement

Collapse
No announcement yet.

Smart Oil Gauge and Homeseer 3

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Smart Oil Gauge and Homeseer 3

    I purchased and installed a Smart Oil Gauge about 2 years ago and have been using the app to monitor. I noticed the other day that someone posted a Node Red code to scrape the website for the status of fuel oil in your tank for Home Assistant.

    https://community.home-assistant.io/...uage/284282/12

    I am clueless when it comes to Node Red but I installed it on my HS3 Windows 10 PC anyway and trying to learn how it works. Is it even possible to run this and have it populate a HS device before I dig too deep and just waste my time?

    I am also open to other alternatives if someone has done this already.

    Thanks

    #2
    You do not need to use Node Red ...just run this python script to generate MQTT messages and you are good to go.

    You can run Python on any Windows OS.

    Code:
    from selenium import webdriver
    import paho.mqtt.publish as publish
    from pyvirtualdisplay import Display
    
    display = Display(visible=0, size=(800, 600))
    display.start()
    
    browser = webdriver.Chrome()
    
    browser.set_window_size(1440, 900)
    
    browser.get("https://app.smartoilgauge.com/app.php")
    browser.find_element_by_id("inputUsername").send_keys("YOUR_ SMART_OIL_USERNAME")
    browser.find_element_by_id("inputPassword").send_keys("YOUR_ SMART_OIL_PASSWORD")
    browser.find_element_by_css_selector("button.btn").click()
    browser.implicitly_wait(3)
    
    nav = browser.find_element_by_xpath('//p[contains(text(), "/")]').text
    nav_value = nav.split(r"/")
    browser.quit()
    print(nav_value[0])
    publish.single("oilgauge/tanklevel", nav_value[0], hostname="YOUR_MQTT_SERVER", port=1883, auth={'username':"YOUR_MQTT_USER", 'password':"YOUR_MQTT_PASSWORD"})
    
    display.stop()
    Note that this is a single message script. Right below the posted script is a multimessage message script.


    Code:
    from selenium import webdriver
    import paho.mqtt.publish as publish
    import json
    from pyvirtualdisplay import Display
    
    display = Display(visible=0, size=(800, 600))
    display.start()
    
    browser = webdriver.Chrome()
    
    browser.set_window_size(1440, 900)
    
    user_name = "YOUR_SMART_OIL_USERNAME"
    password = "YOUR_SMART_OIL_PASSWORD"
    mqtt_server = "YOUR_MQTT_SERVER"
    mqtt_user = "YOUR_MQTT_USER"
    mqtt_password = "YOUR_MQTT_PASSWORD"
    
    
    browser.get("https://app.smartoilgauge.com/app.php")
    browser.find_element_by_id("inputUsername").send_keys(user_n ame)
    browser.find_element_by_id("inputPassword").send_keys(passwo rd)
    browser.find_element_by_css_selector("button.btn").click()
    browser.implicitly_wait(3)
    
    var = browser.find_element_by_xpath('//p[contains(text(), "/")]').text
    fill_level = browser.find_element_by_xpath("//div[@class='ts_col ts_level']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
    fill_level = fill_level.split(r"/")
    current_fill_level = fill_level[0]
    current_fill_proportion = round((float(str(fill_level[0])) / float(str(fill_level[1]))) * 100, 1)
    battery_status = browser.find_element_by_xpath("//div[@class='ts_col ts_battery']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
    days_to_low = browser.find_element_by_xpath("//div[@class='ts_col ts_days_to_low']//div[@class='ts_col_val']//p").get_attribute("innerHTML")
    
    print(current_fill_level)
    print(current_fill_proportion)
    print(battery_status)
    print(days_to_low)
    
    msgs = [{"topic": "oilgauge/tanklevel", "payload": json.dumps({"current_fill_level": current_fill_level,
    "current_fill_proportion": current_fill_proportion,
    "battery_status": battery_status,
    "days_to_low": days_to_low }) }]
    browser.quit()
    publish.multiple(msgs, hostname=mqtt_server, port=1883, auth={'username':mqtt_user, 'password':mqtt_password})
    Then utilize the HS3/4 plugin mcsMQTT to create devices and variables.

    I run an MQTT Python script on a tiny travel router (1" X 2" X .5") used inside of my OmniPro 2 panel can. This script triggers an ESPXXX switch wired to one zone on the alarm panel.

    IE: Below script receives onvif2mqtt/Doorbell/motion and thenPublishes ==> Omni/HikVision_PIR/cmnd/POWER ==> turn on ESP01 Relay which is hardwired to alarm panel from client ==>


    Code:
    BusyBox v1.30.1 () built-in shell (ash)
    
    _______ ________ __
    | |.-----.-----.-----.| | | |.----.| |_
    | - || _ | -__| || | | || _|| _|
    |_______|| __|_____|__|__||________||__| |____|
    |__| W I R E L E S S F R E E D O M
    -----------------------------------------------------
    OpenWrt 19.07.5, r11257-5090152ae3
    -----------------------------------------------------
    
    HAI:/overlay/work# ls
    DB-MQTT-3.py doorbell.txt test2.py
    HikVisionDoorbell.py pubs.py testingpayload.py
    callbacktest.py subs.py work
    calltest2.py test.py
    
    
    work# cat DB-MQTT-3.py
    
    
    import paho.mqtt.client as mqtt
    MQTTv31 = 3
    MQTTv311 = 4
    MQTTv5 = 5
    message = 'ON'
    def on_connect(client,userdata, flags, rc):
    client.subscribe("onvif2mqtt/Doorbell/motion")
    print("rc: " + str(rc))
    
    def on_message(client, userdata, msg):
    global message
    print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
    message = msg.payload
    client.publish("Omni/HikVision_PIR/cmnd/POWER",msg.payload);
    
    def on_publish(client, userdata, mid):
    print("mid: " + str(mid))
    
    def on_subscribe(client, userdata, mid, granted_qos):
    print("Subscribed: " + str(mid) + " " + str(granted_qos))
    
    def on_log(client, userdata, level, buf):
    print(buf)
    
    mqttc = mqtt.Client("petetest",protocol=MQTTv311)
    # Assign event callbacks
    mqttc.on_message = on_message
    mqttc.on_connect = on_connect
    mqttc.on_publish = on_publish
    mqttc.on_subscribe = on_subscribe
    # Connect
    mqttc.connect("192.168.244.150", 1883)
    #mqttc.connect("192.168.1.41", 1883)
    
    # Continue the network loop
    mqttc.loop_forever()
    - Pete

    Auto mator
    Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

    HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
    HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

    X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

    Comment


      #3
      Thanks Pete. Python and MQTT - I got some reading to do. I am sure I will be back to you with some questions.

      Will

      Comment


        #4
        Have a look see here ==>

        How to Use The Paho MQTT Python Client for Beginners

        MQTT and Python For Beginners -Tutorials

        Fill in the blanks for the script above then just run it and use MQTT Explorer or MQTT Explorer for Windows 10 to watch the MQTT messages from your Smart Oil Guage.



        - Pete

        Auto mator
        Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

        HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
        HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

        X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

        Comment


          #5
          Thanks again. Getting into this now...

          Will

          Comment


            #6
            Pete I think I am getting closer. MQTT broker is installed and working. Explorer is connected and listening. I edited the multi-message script, filled in the blanks, found a couple of missing dependencies that I needed to load. Trying to run the script but I can't get by this "FileNotFoundError". How can I find out which file it can't find from this traceback?

            Thanks for your help.

            Click image for larger version

Name:	Capture.jpg
Views:	198
Size:	86.5 KB
ID:	1540290

            Attached Files

            Comment


              #7
              Guessing you already installed ....

              pip install PyVirtualDisplay

              PyVirtualDisplay


              Thinking it relates to using Python in Windows...

              Try adding this to top...not sure if the error is related to "dir" though...


              import subprocess subprocess.call('dir', shell=True)
              - Pete

              Auto mator
              Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

              HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
              HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

              X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

              Comment


                #8
                yes I installed the PyVirtualDisplay prior to running the script. I tried adding that line to the top of your message script and got a DOS Directory but the same file not found error in the trace back Click image for larger version

Name:	Capture.jpg
Views:	181
Size:	204.4 KB
ID:	1540419 .





                Last edited by will40; April 27, 2022, 06:44 AM. Reason: add screenshot

                Comment


                  #9
                  Looks still to be a path error relating to Windows DOS and Python.

                  Look to make sure each file called exist.

                  "get_helptext" p = subprocess.Popen

                  The FileNotFoundError: [WinError 2] Occurred When Use Python Subprocess Module’s Popen() Method.

                  - Pete

                  Auto mator
                  Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

                  HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
                  HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

                  X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

                  Comment


                    #10
                    Personally I would test it on any RPi you have running on your network or utilize a Debian Virtual box installed on your Windows box.

                    I am mostly running Linux these days and only keep Windows 11 going for Wife here. Windows does get in the way.

                    Here run Windows 11 on one Windows tablet and Ubuntu 20.04 on another one. Ubuntu runs much nicer. That said also tried to run the new Windows 11 Ubuntu build and it would cause issues with Windows 11.

                    If you have a ZNet device then SSH to it and install app there.
                    - Pete

                    Auto mator
                    Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

                    HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
                    HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

                    X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

                    Comment


                      #11
                      I have to agree with you that it is a Windows issue Pete. I went through all the python scripts looking for a file being called that wasn't present in any of the folders and found nothing. I struck out and gave up.

                      My son left a Raspberry Pi 3 here when he moved out. I have to say I am a bit ignorant on the subject of RPi and Linux but I am good at following instructions. Let me find it and see what I need to do to load it up and get it on my network. Thanks for the tip.

                      Will

                      Comment


                        #12
                        You can also install Oracle Virtual box on your Windows computer and build a Debian VB to run Linux. Use one core and 1 Gb of RAM to run the VB.

                        Download Oracle VB for your Windows computer here ==> Oracle Virtual Box for Windows

                        Today running an Ubuntu 20.04 VB (not shown on desktop) on house Forum Windows 11 desktop.

                        I can get to the desktop via VPN using RDP to Windows 10-11 or VNC to the Ubuntu computer.

                        Running Ubuntu 20.04 on another tiny computer in house Forum with Window VB's tacked to the telco wall (no monitor or keyboard) with one Windows VB. This box runs Home Assistant and Homeseer (in Linux).

                        Here are Debian images for your VB ==> Debian

                        The script will run fine on an RPi 2,3,4.

                        Here are the RPi images that you would write to an SD card.

                        Raspberry Pi Debian images


                        - Pete

                        Auto mator
                        Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

                        HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
                        HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

                        X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

                        Comment


                          #13
                          I may be off base, but check if it's case sensitive. With some code, "C:\Python310\lib" is not the same as "C:\Python310\Lib"

                          Also, sometimes the back slashes need to be forward slashes, though probably not here.
                          Wade

                          "I know nothing... nothing!"

                          Comment


                            #14
                            Thank you Wade. You are correct.

                            Python in general is case sensitive whatever OS it's running on.

                            You can load Python today in Windows 10 from the Microsoft store.

                            Python 3.8

                            and read this.

                            Get started using Python on Windows for beginners

                            Way much easier to run it on a Linux OS like Debian on an RPi or an OpenWRT OS on a microrouter.

                            Here is a $20 "el cheapo" travel router running OpenWRT and Python.

                            BusyBox v1.30.1 () built-in shell (ash)

                            _______ ________ __
                            | |.-----.-----.-----.| | | |.----.| |_
                            | - || _ | -__| || | | || _|| _|
                            |_______|| __|_____|__|__||________||__| |____|
                            |__| W I R E L E S S F R E E D O M
                            -----------------------------------------------------
                            OpenWrt 19.07.5, r11257-5090152ae3
                            -----------------------------------------------------

                            :~# cat /proc/cpuinfo
                            system type : MediaTek MT7620N ver:2 eco:6
                            machine : Nexx WT3020 (8M)
                            processor : 0
                            cpu model : MIPS 24KEc V5.0
                            BogoMIPS : 385.84
                            wait instruction : yes
                            microsecond timers : yes
                            tlb_entries : 32
                            extra interrupt vector : yes
                            hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
                            isa : mips1 mips2 mips32r1 mips32r2
                            ASEs implemented : mips16 dsp
                            Options implemented : tlb 4kex 4k_cache prefetch mcheck ejtag llsc pindexed_

                            ~# cat /proc/meminfo
                            MemTotal: 60028 kB
                            MemFree: 14584 kB
                            MemAvailable: 17572 kB

                            ~# python3 --version
                            Python 3.7.9







                            - Pete

                            Auto mator
                            Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb

                            HS4 Pro - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
                            HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

                            X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant

                            Comment


                              #15
                              ok I got loaded on RPi along with the display modules and I get this error missing Xvfb.

                              If it is referring to xvfb.py it is located on the RPi in a local folder.

                              Python 3.9.2 (/usr/bin/python3)
                              >>> %Run singlemessage.py
                              Traceback (most recent call last):
                              File "/media/will40/RPi/singlemessage.py", line 7, in <module>
                              display = Display(visible=0, size=(800, 600))
                              File "/home/will40/.local/lib/python3.9/site-packages/pyvirtualdisplay/display.py", line 54, in __init__
                              self._obj = cls(
                              File "/home/will40/.local/lib/python3.9/site-packages/pyvirtualdisplay/xvfb.py", line 44, in __init__
                              AbstractDisplay.__init__(
                              File "/home/will40/.local/lib/python3.9/site-packages/pyvirtualdisplay/abstractdisplay.py", line 85, in __init__
                              helptext = get_helptext(program)
                              File "/home/will40/.local/lib/python3.9/site-packages/pyvirtualdisplay/util.py", line 13, in get_helptext
                              p = subprocess.Popen(
                              File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
                              self._execute_child(args, executable, preexec_fn, close_fds,
                              File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
                              raise child_exception_type(errno_num, err_msg, err_filename)
                              FileNotFoundError: [Errno 2] No such file or directory: 'Xvfb'

                              Anything I can try that might help?

                              Thanks

                              Will

                              Comment

                              Working...
                              X