State operators enable you to style a tool in a much more advanced way than is possible with colorstops. State operators can do more equations, and also use nonnumerical states.
So it is more complex than the colorstop but also has a lot more functionality. State operators are defined in the animations section of the tool.
Basic usage uses the implicit state operator "==", ie tests if state is equal to some value. The below example is from a circle connected to a light entity.
1 2 3 4 5 6 7 8 9101112131415
-type:circleposition:cx:50cy:30radius:22entity_index:0animations:-state:'on'# State equals on?styles:circle:fill:orange# Fill circle background with orange-state:'off'# State equals off?styles:circle:fill:grey# Fill circle background with grey
-type:'circle'position:cx:50cy:50radius:17.5entity_index:0# First entity is index 0show:style:'colorstops'# Format using colorstopscolorstops:# MUST be equal to show style!fill:true# Use the fill property (or stroke)colors:0:'#A8E05F'# Good (0..50) - Green51:'#FDD74B'# Moderate (51..100) - Yellow101:'#FE9B57'# Unhealthy for sensitive groups - Orange151:'#FE6A69'# Unhealthy (101..150) - Red201:'#A97ABC'# Very Unhealthy (201..300) - Purple301:'#A87383'# Hazardous (300 and up) - Brownstyles:circle:transition:fill 0.5s# Take 0.5s to change color
Advanced usage example using JavaScript to determine the state.
This example is from the views that use the weather type and display an animated external SVG to display the current weather type.
As you can see the current state is returned, ie always a match. The usersvg tool then returns the current image which is also a JavaScript template that checks the state of the sun.sun and adds either "day" or "night" to the state to distinguish between day (sun) and night (moon) weather types.
1 2 3 4 5 6 7 8 910111213141516171819202122
-type:'usersvg'id:2entity_index:5position:cx:50cy:50height:13width:13style:'images'images:-clear-night-night:/local/images/weather/clear-night.svg-cloudy-day:/local/images/weather/cloudy-day.svg# < removed a lot of image lines for brevity>-windy-variant-day:/local/images/weather/windy-variant.svg-windy-variant-night:/local/images/weather/windy-variant.svganimations:-state:'[[[return(state);]]]'image:>[[[if (states["sun.sun"].state == 'below_horizon') return (state + '-night');return (state + '-day');]]]