Turn on a UVB lightbulb when UV index is less than 5

I wanted to take a look at this use case again, now that we have released the new Condition to check that a number falls within a range.

The UV index, or Ultra Violet index measurement of the strength of sunburn-producing ultraviolet (UV) radiation at a particular place and time (taken from Wikipedia). It goes from 0 to 11+, and tells you how well you should protect yourself when being in the sun (wear your sunscreen, people!).

In the original use feature request (Condition trigger when number is within a specified range) the apilioer wanted to turn on a UVB light bulb if the UV index was below 5. This was… crafty to implement before, but it’s quite easy today. Let’s take a look at how to set this up, step by step!

:point_right: The goal of the setup

  • If it is between 10AM and 7PM
  • And the UV index is between 0 and 5
  • Then turn on the special UVB lightbulb (we are going to use a UVB bulb that’s on a lamp connected to a TP-link plug)

:spiral_notepad: Step-by-step setup

1. Setting your variables and conditions in Apilio

Timeframe condition:

It’s a timeframe condition between 10 and 19 hours.

UV index variables and condition

Setup a numeric variable for your UV index:
image

And a minimum level (this is a constant, it won’t be updated by any external service):
image

As well as a maximum (this is also a constant):

image

Now create a numeric condition to check if the first variable is between the two constants:

To avoid any false positives, we’ll setup a delay so that only if a value has been stable for 15 minutes, we’ll act on it:

2. Connecting your variable to IFTTT weather channel

We’ll update the UV index variable via IFTTT:

  • Your trigger is the Weather channel UV index going over a certain value, which we’ll set to 0 for our location:

  • Your action is to update a numeric variable in Apilio with the UV index:

  • Save your applet

3. Setting up your Logicblock and actions

We are going to create our Logicblock to control our UVB bulb, first we give it a name:

image

Then we choose as conditions both the time frame and the UV index check conditions, as both have to be true at the same time so it’s a good time to turn it on:

image

image

Now we add our actions:

  1. If the conditions are true, then we turn on the lightbulb
  2. If any of the conditions is false, then we turn off the lightbulb

4. Connecting your actions in IFTTT

This is the final step, well connect the two actions to turn on and off the TP link plug: if you receive the event turn_on_uvb, then you turn on your TP link plug. If you receive the event turn_off_uvb then you turn it off.

Thoughts? :slight_smile:

This was a very detailed example, thanks for making it to the end. This can work for any other example where you need to check if a number falls within a minimum and a maximum in order to trigger your logic. Can you think of other ways you could apply this?

3 Likes