We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Tapo p110 Switched on and off every 5 Minutes?

Options
2»

Comments

  • JohnSwift10
    JohnSwift10 Posts: 501 Forumite
    Fourth Anniversary 100 Posts Photogenic Name Dropper
    GDB2222 said:
    You could just try out ChatGPT's  code and see whether it works. No guarantees, of course, but it's unlikely to cause a major calamity.


     There is no attribute for getState().

      current_state = p110.getState()  # Check if the plug is on or off
    AttributeError: 'P110' object has no attribute 'getState'
  • bob_a_builder
    bob_a_builder Posts: 2,357 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    edited 10 February at 4:35PM
    Since your main issue was to prevent the multiple repetitions of an On command when it was already ON  ( or visa versa) 

    You can set up a variable in your code to record the 'state' of the plug as you see it, 
    where the state reflects what you last set it to and use that the prevent issuing further On commands if already On

    Something like this, pseudo code

    Int state = false
    const  OFF = 1
    const  ON = 2

    Loop
    If temp < 20 and state  != ON then
         turn on heater
         state = ON

    if temp > 20 and state != OFF then
        turn off heater
        state = OFF
  • bob2302
    bob2302 Posts: 558 Forumite
    500 Posts Second Anniversary Name Dropper
    Since your main issue was to prevent the multiple repetitions of an On command when it was already ON  ( or visa versa) 

    You can set up a variable in your code to record the 'state' of the plug as you see it, 
    where the state reflects what you last set it to and use that the prevent issuing further On commands if already On

    Something like this, pseudo code

    Int state = false
    const  OFF = 1
    const  ON = 2

    Loop
    If temp < 20 and state  != ON then
         turn on heater
         state = ON

    if temp > 20 and state != OFF then
        turn off heater
        state = OFF
    As I already pointed out this has no benefit and makes the control slightly less reliable. If, for whatever reason, the code loses track of the remote state, it will lock-up indefinitely. Sending the command unconditionally avoids this possibility without any penalty, since it doesn't affect the number of relay switches. 
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351K Banking & Borrowing
  • 253.1K Reduce Debt & Boost Income
  • 453.6K Spending & Discounts
  • 244K Work, Benefits & Business
  • 599K Mortgages, Homes & Bills
  • 176.9K Life & Family
  • 257.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.