In Jeffery M. Lee's Manifolds and Differential Geometry Exercise 1.77:
For smooth manifolds $X$ and $Y$, show that if $f_0: X \rightarrow Y$ and $f_1: X \rightarrow Y$ are $C^r$ homotopic then there is a $C^r$ map $H: X \times \mathbb{R} \rightarrow Y$ such that $H(x,s) = f_0(x)$ for $s \le 0$ and $H(x,s) = f_1(x)$ for $s \ge 1$
The definition of homotopy had been given only for $H: X\times [0,1] \rightarrow \mathbb{R}$.
But I came up with an example which explains the difficulty with this exercise. Let $X = \mathbb{R}$ and $Y = \mathbb{R}$, $f_0(x) = 0$, $f_1(x) = 1$. Both $f_0$ and $f_1$ are smooth maps, and homotopic via $H(x,s) = s$ where the domain of $H$ is $\mathbb{R} \times [0,1]$. I don't see how you could extend the domain of $H$ to be $\mathbb{R} \times \mathbb{R}$ as the exercise requires since the partial derivative in the $x$ direction would be zero for $s \notin [0,1]$ and suddenly nonzero for $s \in [0,1]$
Somehow I need a general way to make the partial derivatives in the $x$ direction zero at the boundaries.
As you've recognised, the problem boils down to finding a smooth function $g : \mathbb{R} \to \mathbb{R}$ such that $g (s) = 0$ for $s \le 0$ and $g (s) = 1$ for $s \ge 1$.
First, consider the function $\exp ((1 - x^2)^{-1})$. It is in fact a smooth function, and you can show that all it and its derivatives vanish at $x = \pm 1$. We then define $g$ as follows: $$g (s) = \begin{cases} 0 & s \le 0 \\ \int_{-1}^{2 s - 1} \exp ((1 - x^2)^{-1}) \, dx & 0 \le s \le 1 \\ 1 & s \ge 1 \end{cases}$$ The fundamental theorem of calculus then ensures that $g$ is a function with the required properties.