Make the micro:bit decide what to do, using a sensor and an if block.
Street lights switch on when it gets dark, and a fridge beeps when its door is left open. Each one asks a yes-or-no question about a number, again and again.
Last lesson the micro:bit read sensors and showed numbers. Now it will decide. An if block (in Logic) asks a yes-or-no question, such as is the light level less than 50? If the answer is yes (true), it runs the blocks inside. If no (false), it skips them.
Make your prediction first. Help opens once you've locked it in.

basic.forever(function () {
if (input.lightLevel() < 50) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
}
})
This is a night light. < means "less than".
Drag the light slider down to dark, then back up to bright.

basic.forever(function () {
if (input.lightLevel() < 50) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
}
})

basic.forever(function () {
if (input.lightLevel() < 50) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
}
})
Look at what the program does when it is bright.
Add a second if so the lights go off when it is bright. The comparison block is in Logic: choose ≥ (greater than or equal to).
clear screen is in Basic (click more...).
The second question is the opposite one: light level ≥ 50.
Zoe's program:

basic.forever(function () {
if (input.lightLevel() > 50) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
}
if (input.lightLevel() < 50) {
basic.clearScreen()
}
})
Add a second if that clears the screen when it is bright.
This ticks by itself when your blocks do what is asked.
Make the night light come on when the light level is below 100. Change both questions.
Click 50 in each question and type 100.
Add a third if: when the temperature is above 30, show a sad face.
Drag in a third if from Logic.
temperature is in Input. Use > and 30.
Make the night light come on earlier: switch at 100 instead of 50.
This ticks by itself when your blocks do what is asked.
Add a warning: show a sad face when the temperature is above 30.
This ticks by itself when your blocks do what is asked.
Thermometer 1 is above. Thermometer 2:

basic.forever(function () {
basic.showNumber(input.temperature())
})

basic.showNumber(input.temperature())
Make a weather warning. Draw your own pictures:
Test it by dragging the temperature slider.
You need two if blocks inside forever, one for cold and one for hot.
Cold: temperature < 10. Hot: temperature > 30.
Two ifs: a picture when it is cold (below 10) and a different one when it is hot (above 30).
This ticks by itself when your blocks do what is asked.
A fridge should stay at 5 degrees or less. This alarm flashes a cross when it gets warmer. Make it also flash when the fridge is too cold (below 0), with a different picture.
Students use an if block to make the micro:bit decide, and see that a false if does nothing, so turning something off needs its own question. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
An if block asks a yes-or-no question (a condition), such as light level < 50. When the answer is yes (true), it runs the blocks inside; when no (false), it skips them and does nothing. That second half surprises students: in the Predict, the lights come on in the dark and stay on, because nothing tells them to go off. The fix is a second if with the opposite question. The comparison block is in Logic: < less than, > greater than, ≥ greater than or equal to. Next lesson, else does the same job more neatly.
An if does nothing when false, so turning something off needs its own question. Ask them to read the question aloud for a dark room and a bright one.
Stretch: Make the night light dim gradually: one row lit when it is a bit dark, three rows darker, all five in the dark (three ifs).
Support: Give students the second if already in place with an empty question, and ask them to choose the comparison.
Next lesson: else, which turns two ifs into one block with no gap. Class ideas: a classroom 'too noisy' light with the sound level (micro:bit V2); a plant monitor on a windowsill with a real micro:bit.